Save .nrrd file into STL file

Can we save full .nrrd file to STL file without doing any segmentation ?

If your nrrd is binary (i.e. contains a segmentation) then you can load it as a labelmap (click Show Options in the load window and check LabelMap option). Then go to Data module, right-click the labelmap, select Convert labelmap to segmentation node. Then go to the Segmentations module, select the segmentation, go to the very bottom to the Export to files section, then select your options and click Export.

Thanks @cpinter,
Can I also write the segmentation node as stl from python code?

Yes, using one of these functions:

1 Like

I tried to export an nrrd segmentation to an stl file using ExportAllSegmentsToModels function. I searched for similar examples and here is how I tried to do it, but it still doesn’t work, any ideas?

    #loading DICOM image and its nrrd segmentation
    imgNode = DiskSimulator.load_image(dicomPath, "dicom file")
    nrrdNode = slicer.util.loadSegmentation(nrrdPath)

    #creating labelmap from segmentation
    segmentationNode = slicer.vtkMRMLSegmentationNode()
    slicer.mrmlScene.AddNode(segmentationNode)
    segmentationNode.CreateDefaultDisplayNodes()
    segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(imgNode)
    segmentationNode.GetSegmentation().AddSegment(nrrdNode.GetSegmentation().GetSegment("Segment_1"), "bone1")
    segmentationLblmap = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode", "segmentations")
    slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, segmentationLblmap,  imgNode)         
    
    #preparing to run the function ExportAllSegmentsToModels
    shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
    exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), "E:\\segmentations\\bone1.stl")
    slicer.modules.segmentations.logic().ExportAllSegmentsToModels(segmentationNode, exportFolderItemId)

This segmentation export function does not mean export to files. It means export to model nodes. After executing your code you should find the models in the folder item you created in Subject hierarchy (Data module). Then you can save the models to files from there.