# Place fiducial at centroid of current slice

**URL:** <https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169>\
**Category:** Support\
**Created:** [February 24, 2022, 9:23pm UTC](https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169 "2022-02-24T21:23:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmhuie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jmhuie/32/7086_2.png) [@jmhuie](https://discourse.slicer.org/u/jmhuie)\
**Post date:** [February 24, 2022, 9:23pm UTC](https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169/1 "2022-02-24T21:23:23Z")

</div>

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)

 ![Screen Shot 2022-02-24 at 4.20.41 PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba51e29958160dba6db50c3a8b648decb3888997.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 25, 2022, 7:27am UTC](https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169/2 "2022-02-25T07:27:56Z")

</div>

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](https://github.com/vmtk/SlicerExtension-VMTK/blob/master/CrossSectionAnalysis/CrossSectionAnalysis.py#L1094-L1154) in the [Cross-section analysis module](https://github.com/vmtk/SlicerExtension-VMTK/blob/master/Docs/CrossSectionAnalysis.md) 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.

---

<div class="post-metadata">

**Author:** ![jmhuie](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jmhuie/32/7086_2.png) [@jmhuie](https://discourse.slicer.org/u/jmhuie)\
**Post date:** [February 27, 2022, 3:57pm UTC](https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169/3 "2022-02-27T15:57:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [July 17, 2022, 4:01am UTC](https://discourse.slicer.org/t/place-fiducial-at-centroid-of-current-slice/22169/4 "2022-07-17T04:01:16Z")

</div>

I also want to know howto get the centroid…
