Recreating segmentation from 3D models

Let’s say I have the original volume, and the segmentation object saved as a 3D model (like ply) on the disk, but not the actual seg.nrrd file.

What is the suggested operation to reconstitute the segmentation map close to the original detail for further edits?

According to this document (slide N° 5), you should be able to convert back and forward from labelmap representation to surface representation without any information loss

That’s what I thought, but wasn’t able to discover a way to do so. I tried creating a empty segment from the source volume I used to generate the model, and then use the import/export feature of the segmentations module to import the model into that blank segment use a labelmap.

Unfortunately, that’s not the same resolution at all, it ended up being fairly low res.

According to this example, it may be compulsory to set the geometry information for the segmentation

That’s the part I am confused about. By creating a blank segmentation from the source volume, I assumed that the imported segmentation will inherit that geometry, but that’s not what I am seeing in experience.

Also for 3D models import/export feature of the Segmentations does not have a setting where you can put a reference volume to get the geometry from.

I must be overlooking something…

@muratmaga can you share a concrete example (a volume and model) and describe the steps you take? At first I thought you were asking about registering the model to the volume, but I guess you are more concerned about the resolution of the rasterized model?

It boiled down from which stage the models were exported. If you kept the smoothing option on when you enabled the Show 3D button, and then export the model, you irrecoverably lost detail.

  1. Download the CTChest sample data, and segment bones (threshold 165-Max, closing filter 5, island tool to keep the largest island). Save the segmentation as seg.nrrd
  2. Turn off smoothing in Show 3D button, then right-click on the segment in SH and export this segmentation as a model, export the model as ply.
  3. Repeat the #2 but smoothing enabled (with default 0.5)
  4. Reset the scene, reload the model the and the CT volume into the scene and try to create a high-resolution segmentation out these models.

When import #3 it is lower resolution than the labelmap generated from #2. In fact for me the import step #2 is 3-4 times longer than the one with smoothing enabled. You will see the difference in the labelmaps, not much for this low resolution sample data, but enough for us to make a difference for landmarking certain faint structures on dry bones such cranial sutures or small protuberances.

Unfortunately for this data, I think they were all exported with smoothing enabled, so I can’t find a way to generate higher detailed labelmaps version from them.

The code below creates a new segmentation, updates its geometry sampling with the volume node and imports a model. There are more details with the test CT-chest volume, following the steps you described. The difference appears when the Show 3D button is deactivated/activated in the segment editor, whether the code is run or the model is imported in the Data module. The difference is even more important if the model has been saved without 3D smoothing.

I have no idea how far it may be helpful to you.

def createSegmentationWithGeometryAndImportModel():
  volume = getNode("CT-chest")
  segmentation = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
  segmentation.CreateDefaultDisplayNodes()
  segmentation.SetReferenceImageGeometryParameterFromVolumeNode(volume)

  segGeomLogic = slicer.vtkSlicerSegmentationGeometryLogic()
  segGeomLogic.SetInputSegmentationNode(segmentation)
  segGeomLogic.SetSourceGeometryNode(volume)
  segGeomLogic.CalculateOutputGeometry()
  segGeomLogic.ResampleLabelmapsInSegmentationNode()
  segGeomLogic.SetReferenceImageGeometryInSegmentationNode()
  
  model = getNode("SmoothedPLY") # NoSmoothedPLY afterwards.
  segLogic = slicer.modules.segmentations.logic()
  segLogic.ImportModelToSegmentationNode(model, segmentation)

ImportModel

1 Like