Origin of painted object is modified when the object is saved to dicom and loaded into Slicer

Hi all, I have the following situation when working with a dataset where a MR has been fused to the base CT scan:

  1. In the MR, I paint a segmentation object in the segment editor via the sphere brush and print the origin of the object (see below for code)

  2. I save the segmentation object to my local machine and load it again into slicer via the DICOM module. The origin of the loaded object does not coincide with the origin of the painted object, although the objects are shown on top of each other in the views.

This is the code to retrieve the origin:

segm = node.GetSegmentation()
binaryLabelmapPresent = segm.CreateRepresentation(
            slicer.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName())

segment = segm.GetNthSegment(0)
labelMapName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationBinaryLabelmapRepresentationName() 
vtkOrientedImageData = segment.GetRepresentation(labelMapName)
origin = vtkOrientedImageData.GetOrigin()

Do you see a problem with the code or can you please explain why the two origins differ?

Origin of an segment representation inside a segmentation is an internal implementation detail. What is guaranteed that the physical location of voxels remain the same. Extent, origin, and axis directions may change as you manipulate segment or you save the file (as you need to consolidate all segments into a single 3D/4D array).

If you want a voxel array in a particular geometry then specify a reference geometry (volume node) when you export the segment into a labelmap.