Convert model to segmentation node

Hi, I have a labeled surface model of a pelvic floor (47 labels in a single file, but labels separated):


If I make a segmentation, all segmented labels have the same color:
image
The same output appear by reading VTK or STL or whatever. Any help, how can I make a segmentation having particular segments distinguished by colors (I mean segmentation labeled too)?

Please describe how the file was generated and how the labels are represented.

To make them into a Slicer segmentation you may need one file per segment and then merge them into a single segmentation with the Move/Copy option in the Segmentations module. It may be easier to write a script for this, but it could be done with the GUI.

I am writing it as a script (Slicer module). The file was converted by my script from a third-party software. I can convert to any format, currently I tested STL and VTK. I prefer VTK as I don’t loose the information on node numbering. In case of STL, it has the labels separated as solids, in case of VTK, it is an unstructured grid by labels distinguished by celldata. The same result appears with VTK polydata (labels distinguished by celldata).

The story behind is that I have a input file from a third-party software, I want to import the data into Slicer (that’s why I convert to VTK), make some corrections (morphing) and export it back for calculation.

I wanted to avoid multiple files, so is it necessary to have a file per label? Thank you.

Oh good, if you are writing a script it should be pretty straightforward. The API of the segmentation infrastructure is very extensive and nicely documented. You should just need to use AddSegmentFromClosedSurfaceRepresentation and similar methods. If you do the whole process in Slicer you don’t need to use files at all.

Thank you, but still fumbling… Returning to your first answer, does it mean that Slicer doesn’t recognize segments in a single file and I need one file per each segment anyway, even by scripting approach? But it seems to me that Slicer must somehow recognize the segments from a single file, because it assigns colors to them upon reading…

Since you are starting with a triangle mesh (a polydata in vtk terminology) you can associate values with points and display them using a lookup table (either continuous or discrete) when loading the data as a Model in Slicer. But when loading the file as a Segmentation, these scalar value are not considered. I don’t recall ever seeing files that used point scalars to indicate segments, so it’s probably not a standard approach or at least it’s not something we support currently. But you can write a script to handle this case.

2 Likes

I’d probably try this:

  1. Write a script that uses vtkSelectPolyData to create individual polydata objects for each label
  2. Create a vtkMRMLModelNode for each per-segment polydata
  3. In Data module create a folder and move all these models into it
  4. Right-click folder and convert the models to a segmentation
1 Like

If you don’t need to edit your colored mesh in Segment Editor then you can load it as model. Slicer can use the associated point or cell scalars for coloring the model. If you want to edit segments using Segment Editor then you can follow Csaba’s instructions above; or save the segments as a multiblock data set with segmentation-specific metadata that Slicer can directly load as segmentation.

Note that in the segmentations infrastructure of Slicer we chose to store closed surface representation of a segmentation as a multiblock dataset (and not as a simple polydata with cell scalars). This makes it is easier and less computationally expensive to extract each segment. This may matter when you work with atlases that have hundreds of segments.

1 Like

Thank you, all, I will try to proceed accordingly. Ludek