# Segmentation Using SimpleITK

**URL:** https://discourse.slicer.org/t/segmentation-using-simpleitk/13232
**Category:** Support
**Created:** [August 29, 2020, 2:12pm UTC](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232 "2020-08-29T14:12:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Fereshte\_J](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fereshte_j/32/7898_2.png) [@Fereshte\_J](https://discourse.slicer.org/u/Fereshte_J)
#### Post date: [August 29, 2020, 2:12pm UTC](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232/1 "2020-08-29T14:12:13Z")

</div>

Hello, I wanted to know whether it is possible to create a mask for an image using simpleitk and use that mask to show the segmented region in slicer jupyter kernel.  
thank you.

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [August 29, 2020, 2:21pm UTC](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232/2 "2020-08-29T14:21:44Z")

</div>

This easily doable in two steps:

- push/pull volume node to/from SimpleITK using sitkUtils (see [example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Running_an_ITK_filter_in_Python_using_SimpleITK))
- convert the volume node to/from segmentation node (see [example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create_a_segmentation_from_a_labelmap_volume_and_display_in_3D))

There are several Segment Editor effects that use SimpleITK, which can serve as a complete example (that even show how to implement interactive segmentation tools, which require some user input):

> <https://github.com/lassoan/SlicerSegmentEditorExtraEffects/blob/master/SegmentEditorWatershed/SegmentEditorWatershedLib/SegmentEditorEffect.py#L106-L133>

---

<div class="post-metadata">

### Author: ![Fereshte\_J](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fereshte_j/32/7898_2.png) [@Fereshte\_J](https://discourse.slicer.org/u/Fereshte_J)
#### Post date: [August 31, 2020, 5:12am UTC](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232/3 "2020-08-31T05:12:01Z")

</div>

Thank you for your reply. However, I have another problem. I am using a UNET neural network to segment a series of CT images and save the segmented image as a different file. When I use matplotlib to show the segmented image, the regions of interest are clearly visible with a distinct color, however when I import the image into the slicer and display it is nothing like the segmented one. I have attached the plots from matplotlib and slicer. Can you help me to be able to display the segmented image in the slicer, too?

 ![matplotlib](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/0/701450d1e4976012e84849c4f195eea63aff4a11.jpeg) ![slicer](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8a2238a60e57170cf2e65aff0383ec9eef3fb29c.jpeg)

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 1, 2020, 2:58am UTC](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232/4 "2020-09-01T02:58:45Z")

</div>

> [@Fereshte\_J](#):
>
> segment a series of CT images and save the segmented image as a different file

Can you send this saved image (upload somewhere and post the link)?

> [@Fereshte\_J](#):
>
> when I import the image into the slicer and display it is nothing like the segmented one

How do you do this exactly?
