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

**URL:** <https://discourse.itk.org/t/running-itk-snap-with-image-and-segmentation-by-simple-itk-image-viewer-class/5215>\
**Category:** Algorithms\
**Tags:** simpleitk\
**Created:** [July 26, 2022, 9:03am UTC](https://discourse.itk.org/t/running-itk-snap-with-image-and-segmentation-by-simple-itk-image-viewer-class/5215 "2022-07-26T09:03:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oguzcan13](https://discourse.itk.org/letter_avatar_proxy/v4/letter/o/8797f3/32.png) [@Oguzcan13](https://discourse.itk.org/u/Oguzcan13)\
**Post date:** [July 26, 2022, 9:03am UTC](https://discourse.itk.org/t/running-itk-snap-with-image-and-segmentation-by-simple-itk-image-viewer-class/5215/1 "2022-07-26T09:03:22Z")

</div>

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 ;

```auto
viewer = sitk.ImageViewer()
viewer.SetCommand('/home/oguzcan-bekar/Downloads/itksnap-3.6.0-20170401-Linux-x86_64/bin/itksnap')
viewer.Execute(image)
viewer.Execute(mask_array)

```

But this is shown individually image and segmentation in ITK-Snap. (2 window)

```auto
subprocess.run(['/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.

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 27, 2022, 7:16pm UTC](https://discourse.itk.org/t/running-itk-snap-with-image-and-segmentation-by-simple-itk-image-viewer-class/5215/2 "2022-07-27T19:16:51Z")

</div>

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")

subprocess.run( ['/Users/dchen/Applications/ITK-SNAP.app/Contents/MacOS/ITK-SNAP',
                 '-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.
