Resampling Segmentation and Volume about a User-Defined Axis For Plotting

Hi,

I have segmented a CT scan of the proximal femur as shown below.
image
I am looking to plot the cross-sectional area of this segmentation along the axis of the femoral neck using SliceAreaPlot.py ((https://gist.github.com/lassoan/62370c6b0552f7df1111eb7fc37abfd2).
Currently, the code only allows calculation in the coronal, axial, or sagittal planes. Thus, I need help reorienting my segmentation and volume along the axis of the femoral neck.

For a first try, I first reoriented the axes by applying a linear transform to my segmentation and volume as shown below.
image
I then applied the SlicePlotArea.py code. However, the plot did not take the transform into account and instead plotted the original axis.

I am looking for another method to try. I believe I need to resample my segmentation and volume, but I’m not sure how to do this. When I tried using Resample Scalar/Vector/DWI Volume Module along with my transform, all of my views became black. image

Please provide some help!

Thanks,
Abby

Did you try hardening the transform before running SliceAreaPlot?

Since a linear transform is applied, hardening would not resample the volume.

A simple solution would be to create an ROI node, rotate it with a transform so that it is aligned with the axis directions that you need and use that in Crop volume module to crop/resample the volume.

You can set up the transform manually, using sliders and/or interactively moving/rotating in a 3D view (in Transforms module, enable Display / Interaction / Visible in 3D view). Or, create the ROI automatically from an open curve node (in recent Slicer Preview version) by dropping a curve point in the middle of the femur head, a second point along the femur, and copy-pasting this code into the Python console:

femurLineNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsCurveNode")
femurToWorldMatrix = vtk.vtkMatrix4x4()
femurLineNode.GetCurvePointToWorldTransformAtPointIndex(0,femurToWorldMatrix)
femurToWorldTransform = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode")
femurToWorldTransform.SetAndObserveMatrixTransformToParent(femurToWorldMatrix)
roiNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLAnnotationROINode")
roiNode.SetXYZ(0, 0, 30)
roiNode.SetRadiusXYZ(40, 40, 60)
roiNode.SetAndObserveTransformNodeID(femurToWorldTransform.GetID())

Choose Open Curve on toolbar then click the first curve point:

Go to a different slice, place the second contour point then right-click to finish the curve:

Copy-paste the code snippet above to automatically generate ROI:

Use Crop Volume module (you can leave all settings at default) to crop&resample the volume using the oriented ROI:

You can rotate slice views to align with volume axes by clicking pushpin icon at the top-left corner of the slice view controller and clicking “Rotate to volume plane” button.

You can then perform cross section analysis using this cropped volume.

Thank you very much for the detailed response Andras! I was able to get the SliceAreaPlot code to work along my defined axis using the methods you described. I opted to manually set-up the ROI node and transform.

I greatly appreciate the help!

Best,
Abby

1 Like