Get IJK from Slice Offset after Rotate to Volume Plane

Hello Slicer Community,

My ultimate goal is to create a button that copies a manual segmentation from the slice below/above and copies it into the current slice (presumably axial/Red SliceView). Note that due to the problems with segmenting on oblique views, I always use the “Rotate to Volume Plane” function after loading a Volume.

My plan of attack was to

  • Get the Red, Yellow, Green coordinates with
layoutManager =
offsets = []
for sliceViewName in ['Red','Yellow','Green']:
  sliceWidget = layoutManager.sliceWidget(sliceViewName)
  sliceWidgetLogic = sliceWidget.sliceLogic()
  offset = sliceWidgetLogic.GetSliceOffset()

z,x,y = offsets
  • Use the z (“Red”) offset and use RAS to IJK to get the slice level
  • Copy the z-1 or z+1 slice from the segment array onto the current z slice
  • Update the segment in order to finalize the “copy”

However, after doing “Rotate to Volume Plane”, the slice offsets can no longer be used to get the IJK coordinates because the Direction matrix has changed.

There are two ways of solving my problem, but I’m not sure which one is easiest/doable in Slicer

  • Instead of getting the slice offset, simply get the current ‘k’ slice from the Red SliceView, if this function exists. (After “Rotate to Volume Plane” all Offsets correspond to a unique z coordinate).
  • Get the transformation from “Rotate to Volume Plane” in order to transform my Red Slice Offset from the “Rotate to Volume Plane” space to the “World” space to “Voxel” space.

Thank you for any tips or comments!

Copying content of previous slice is not implemented in Segment Editor because it could either cause huge bias in the segmentation (you would tend to accept the suggested contour as is) or increase segmentation time (since it usually takes much more time to fix a contour then draw it from scratch) or both.

Therefore, for cases when contours of a segment does not change very quickly between neighboring segments, we suggest to use “Fill between slices” effect. You can segment on as many slices as you want then review the interpolated segmentation, and make fixes (by providing complete segmentations on additional slices) and so you avoid bias and keep segmentation time at a minimum.

If you still want to implement copy from previous slice then you can find IJK<->RAS conversion sample code in the script repository. For oblique views, voxels of previous/next slice is not well defined, as some of the volume voxels are always shared between neighbor slices.

Thanks for your answer @lassoan,
I completely agree with you. I’m not a huge fan of this feature, but unfortunately, it was something that was asked of me.
As you point out, the IJK<->RAS conversion is not simple because of the oblique views. As I tried to explain in my previous post, I think I may have found a way around this, but I would need the transformation matrix after performing “Rotate Volume to Plane”. This matrix would take me from the “Rotate Volume to Plane” space to the “Oblique” space. In other words, using the offsets from the Red, Yellow, Green once the Volume has been rotated to the plane, I could get their equivalent in the Oblique space (i.e., how the volume shows up in Slicer by default). Then, using the RAS<->IJK matrix of the volumeNode, I could get the ‘k’ slice that I see when the volume is Rotated to Plane.

I hope this makes sense. To summarize, is there a way to get the transformation performed on the image when “Rotate Volume to Plane” has been performed?