How to get a segment in a vtkImageData whithout location issue

Hi everyone!

I would like to get a segment from a segmentation node as a vtkImageData (not a vtkOrientedImageData).

My pipeline is:

  1. I create a segment from a binary vtkImageData
  2. Then I modify this segment in the segment editor
  3. I want to get back that segment after these modifications in the vtkImageData I had before (in step 1)
  4. To check, I create a new segment from the vtkImageData with the modifications done (got from step 3)

I am currently doing this:

std::string segmentID = “…”;
vtkOrientedImageData* labelmap = segmentationNode->GetBinaryLabelmapRepresentation(segmentID);
vtkImageData* image;
image->DeepCopy(labelmap);

My problem is that the vtkImageData (“image”) I get back has a spacing and an origin not set to 0 (I was told that for a vtkImageData it has to be 0) and that if I create a new segment from that image the two segmentations don’t match, meaning the shape is the same but the location is not, see: the blue segment is the one I have in Slicer after using tools in the segment editor and the yellow one is the one created from the vtkImageData I get back (I want them to be the same)

I’m not sure how to deal with this location problem

Thanks for your help,
Marine.

Unfortunately, VTK cannot store orientation information in vtkImageData. Therefore you either have to store image in a vtkOrientedImageData object; or store origin+spacing+orientation in a separate matrix and store pixels in vtkImageData (setting spacing to (1,1,1), origin to (0,0,0) in the vtkImageData). It might be tempting to just ignore the image orientation and use a vtkImageData object to store spacing and origin but this approach completely fails when an image is not axis-aligned.

In the long term we’ll try to get vtkOrientedImageData integrated into VTK, but until then you have to learn how to convert between these two representations. There are lots of examples for processing vtkOrientedImageData using VTK filters in segment editor effects:

Ok, I’ll see what I can do with these information.

Thank you !