Aligning segmentation volume with image volume in code using nrrd headers

Hello, I am working on prostate segmentation in Slicer. After finishing the segmentation and saving the Scene, I took a look at the image volume (V) and the segmentation volume (S) nrrd files in python, the two volumes have the same orientation as I performed segmentation on axial slices (on the RA plane) and moved in the Superior-Inferior axis, segmenting one slice at a time.

Both V and S have ijk-to-ras matrices that enable me to recreate their relative location in space as shown in the figure below:

image

For a given a slice in V, I would like to find the corresponding slice in S in my code (or none if no intersection). Since I know that the two the volumes have the same orientation in space, I was thinking of simply taking one slice in V and check which slice in S is coplanar. I can do this by taking one point for each slice in S, so if S has 10 slices I have 10 points to compare with the current slice in V. Does this make sense? Or is there a simple way to achieve this?

Thank you

You can get the slice coordinates very easily by converting voxel coordinates to LPS and LPS to voxel coordinates of the other volume:

point_IJK_S = inv(IJKToRAS_S) * IJKToRAS_V * point_IJK_V

You mean RAS right? to RAS…

If you have a slice number (typically K coordinate) in one image and you need slice number in another image then you need to convert IJK->RAS->IJK (or IJK->LPS->IJK).

Got it. Makes sense, simpler than what I had in mind, thank you so much Andras!

A post was merged into an existing topic: Aligning Segmentations and images using python