First of all, it is best to use the actual module logic, that has the MRML scene and everything: segmentationsLogic = slicer.modules.segmentations.logic()
Second, I’d check if the output image actually contains a meaningful image, just for the sake of debugging. For example like this: acc = vtk.vtkImageAccumulate() acc.SetInputData(outputImageData) acc.SetIgnoreZero(1) acc.Update() acc.GetVoxelCount() # Get number of non-zero voxels (should be >0) acc.SetIgnoreZero(0) acc.Update() acc.GetVoxelCount() # Get number of all voxels (should be different than the non-zero one) acc.GetMin() # Should be 0 acc.GetMax() # Should be 1000
Third, what is the return value of the last call? True or False? if it’s false, is there any error in the log? Circle button with X in it in bottom right corner, or whole log in Help/Report a bug.
Fourth, I think I found a bug that might explain the problem if the above three are all good. I did this to get the IDs in the segmentation: ids=vtk.vtkStringArray() segmentationNode.GetSegmentation().GetSegmentIDs(ids) ids.GetValue(0)
and it is not the same as segmentPrintId, which should be. It seems that the names and IDs are not handled correctly by vtkSegmentation::AddEmptySegment. I will debug into it and see what the exact problem is.
For a short term solution you can just get the IDs the same way I did for testing.