Place fiducial at centroid of current slice

Hi All,

I am trying to create a python script that will place a fiducial at the centroid of a currently visible slice of a segment. Unfortunately, I am running into a few road blocks. Specifically, I am not sure how to grab the current slice number and coordinates of the segmented pixels that are currently contained in it to calculate the centroid. I need to be able to do this on the fly for both transformed and untransformed volumes. Any insights or suggestions would be greatly appreciated.

Here is an example photo (not much to actually see)

In general, there is no such thing as slice number in this case, as the slice view normal does not have to be parallel to any of the segmentation axes.

Instead, what you need is to extract a cross-section from the segment using the slice’s SliceToRAS transform. You can see an example how it is done for segmentation closed surface representation in the Cross-section analysis module in SlicerVMTK.

Cross-section analysis module may be potentially interesting for you, as it allows convenient reslicing of segments along a line (it can be straight or curved) and measures cross-sections, finds minimum/maximum cross-sectional area, exports results to a table, etc.

Thanks Andras,

The SlicerVMTK extension does seem very relevant, but on first glance I don’t fully understand what it is doing.

Instead, I have designed a work around that seems to work pretty well for now. I’m essentially 1) creating an MarkupsRoI around the desired “slice” or “index”, 2) creating a blank scalar volume that matches those dimensions, 3) export a labelmap of the segment with the dimensions of the blank reference volume, 4) converting the labelmap to a segmentation node and then calculating the centroid of the “slice”.

I will admit that it sounds a bit clunky and there’s a slight delay with larger volumes, but I do not think it’s much slower (if at all) than the VMTK cross-section analysis module when handling larger volumes

I also want to know howto get the centroid…