# Reference location information for segment with respect to master volume

**URL:** <https://discourse.slicer.org/t/reference-location-information-for-segment-with-respect-to-master-volume/3133>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [June 10, 2018, 11:29am UTC](https://discourse.slicer.org/t/reference-location-information-for-segment-with-respect-to-master-volume/3133 "2018-06-10T11:29:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRXCAT\_CMR](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@MRXCAT\_CMR](https://discourse.slicer.org/u/MRXCAT_CMR)\
**Post date:** [June 10, 2018, 11:29am UTC](https://discourse.slicer.org/t/reference-location-information-for-segment-with-respect-to-master-volume/3133/1 "2018-06-10T11:29:41Z")

</div>

Operating system: Windows 10  
Slicer version: 4.8.1 (r26813) built myself

I am currently working on some extension submodule to Segment Editor doing automatic segmentation of some organs. This involves handling multiple segments mostly working with numpy arrays. This is currently done as follows inside a SegmentEditor effect method:

```
# get master volume array
volumeNode = slicer.util.getNode('CT image')
npImage = slicer.util.arrayFromVolume(volumeNode)

# get mask array
segNode = slicer.util.getNode('Segmentation') # Get the segmentation node    
npMask = slicer.util.arrayFromSegment( segNode, 'Airways')

```

My question: The npMask array is smaller than the npImage array. Where can I get information about how they relate spatially?  
Or more precisely: where in npImage is the lower left corner of npMask located?

---

<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:** [June 10, 2018, 2:02pm UTC](https://discourse.slicer.org/t/reference-location-information-for-segment-with-respect-to-master-volume/3133/2 "2018-06-10T14:02:31Z")

</div>

Origin, spacing, axis directions, and extents of binary labelmap representation for each segment is stored in the vtkOrientedImage data object in the corresponding vtkSegment object. You can use `GetBinaryLabelmapRepresentation` convenience method in segmentation node to get this image directly, as it is done in the [`slicer.util.arrayFromSegment`](https://github.com/Slicer/Slicer/blob/f051e24c803ae0a067e04ea2b2a9a178040d7415/Base/Python/slicer/util.py#L829-L844) method.

Segment editor takes care of getting the master volume and resample to the segment’s geometry (so you don’t need to worry about matching voxels of the master volume and your segment; origin, spacing, and axis directions will be the same; only their extent may be different), updating voxels in of all segments by respecting masking settings, etc. Therefore, instead of trying to implement an effect from scratch, I would recommend to find the effect that is most similar to what you would like to do and modify/extend that. Most segment editor effects are implemented in Python, so there are plenty of examples. Source code:

- [https://github.com/Slicer/Slicer/tree/master/Modules/Loadable/Segmentations/EditorEffects/Python](https://github.com/Slicer/Slicer/tree/master/Modules/Loadable/Segmentations/EditorEffects/Python) (source code of all built-in effects that are implemented in Python)
- [https://github.com/lassoan/SlicerSegmentEditorExtraEffects](https://github.com/lassoan/SlicerSegmentEditorExtraEffects) (this also shows how to define additional custom effects in an extension that show up in the Segment Editor)
