How to export individual slices or calculate a centroid for each slice of a segmentation?

I have some medical images, saved as .nrrd files. (segmented)

I would like to calculate the centroid for each slice along a single axis. (Entire segmnet is currently aligned)

Then create a line of best fit for this.

Any suggestions for this please,(I am very much a beginner and not of engineering background.)

Alternatively if I can export single slices as .png I think there is some function in matlab to do that. I am not sure how to export png files each slice. I use Mac with Mac OS 11.

Slicer 4.11

Thanks heaps

You can get the segmentation as a 3D voxel array and access each slice using indexing. But most likely you will not need to deal with such low-level operations.

What is your overall goal? Would you like to extract the centerline of a segmented structure? Have you tried the VMTK extension for this or SegmentGeometry extensions?

Thanks @lassoan, I think segment geometry extension has it,

Yes, I would lilke to extract the centreline of the structure,
Based on centroid of every slice of the segmentation.

So I selcetd computations as centroid (screenshot), I think Cx and Cy is the x and y coordinates of the centroid for each slice. Is that correct?

But I place a fiducialmarker the possible centroid, on a particlar slice, I get different coordinates for the marker,
I think the module does what I want but I am not interpreting it correctly. Could you pls advice.
Also how can I draw a best fit line for the series of centroids pls

Thanks a lot

See documentation:

  • Cx: Centroid x-coordinates that correspond to the resampled and cropped volume exported by SegmentGeometry. Presented in IJK format.
  • Cy: Centroid y-coordinates that correspond to the resampled and cropped volume exported by SegmentGeometry. Presented in IJK format.

IJK refers to voxels coordinates. You can compute world (RAS) coordinates from voxel coordinates of a volume as shown in this example.

You can compute best fit line using SVD (see example in SlicerHeart). You can draw the computed line using a line markup.

Thanks very much @lassoan

Works well

1 Like