Running ITK-Snap with image and segmentation by Simple ITK Image Viewer Class

Hi there my question is quite basic actually but I couldn’t find the is there any way or not?

I have Dicom image series and Prediction of Segmentation with .jpeg files. Basically, I am able to read them by SimpleITK but when I want to show them together I couldn’t find the solution.

Trials ;

viewer = sitk.ImageViewer()

But this is shown individually image and segmentation in ITK-Snap. (2 window)['/home/oguzcan-bekar/Slicer-5.0.2-linux-amd64/Slicer', '--python-code', 'slicer.util.loadVolume' , '(', '/home/oguzcan-bekar/Desktop/PyQt/image.nii.gz', ')', ';',
#                 'seg', '=', 'slicer.util.loadSegmentation', '(','/home/oguzcan-bekar/Desktop/PyQt/mask.nii.gz', ');', 'seg.CreateClosedSurfaceRepresentation();'], shell=False)

The 3D Slicer is running but I think because of subprocess error is not able to show images and segmentation as a combined.

What is the best way to run python code to show up image and segmentation together?

Thank you very much.

Yeah, the SimpleITK ImageViewer isn’t designed to visualize a segmentation mask. Combining your two attempts, I wrote an example that uses ITK-SNAP. It also uses subprocess to launch Snap, so I can give the image and segmentation via the command line:

import subprocess
import SimpleITK as sitk

sphere = sitk.GaussianSource( sitk.sitkUInt8, size=[64,64,64], sigma=[32.,32.,32.],
                              mean=[32.,32.,32.], scale=200 )

mask = sphere>150

sitk.WriteImage(sphere, "sphere.nii.gz")
sitk.WriteImage(mask, "sphere-mask.nii.gz") ['/Users/dchen/Applications/',
                 '-g', 'sphere.nii.gz',
                 '-s', 'sphere-mask.nii.gz'] )

Another idea, if you’re using Jupyter Notebooks is to use ITK-widgets. IIRC it can handle segmentation masks.