Batch conversion of .nrrd to models

Hi,

I have a batch of segments-.nrrd files. (100s)
I would like to load them (Add data- files) as .nrrd. (The default in add data dialog box is volume, so I manually change them to segmentations, one by one. (So they load as segmentations)

Then I have to convert them to models. Here also I either do it one by one in the data module by right click, convert to models or in segmentations module by exporting to models.

Is there an efficient way to do this, without going one by one.

  1. Load as segmentations (When default is volume)
  2. Export to models

Thanks

You can write a short python script to do the above

segmentationNode = slicer.util.loadSegmentation(YOUR_FILE_NAME)  # load the data as a 

# Export segmentation to model
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
exportFolderItemId = shNode.CreateFolderItem(shNode.GetSceneItemID(), "Segments")
slicer.modules.segmentations.logic().ExportAllSegmentsToModels(segmentationNode, exportFolderItemId)

There are more examples you can take a look at in the python Script Repository.

-Andinet

1 Like

Thanks @Andinet_Enquobahrie

Tried , but does not load as a batch, does it?
I ve got 100s of.nrrd files in one folder, wanting them to load/ change at once.

Thanks

If you combine the code provided by @Andinet_Enquobahrie with a for loop that traverses all files in a directory then you’ll end up with a script that does just what you want.

Thank you very much, @cpinter and @Andinet_Enquobahrie

I tried learning that, doing a loop

Sorry I am a medical person, couldn’t get to doing a loop.

Thanks