# How to process only few slices of a 3D dicom image

**URL:** <https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233>\
**Category:** Engineering\
**Tags:** dicom\
**Created:** [September 9, 2019, 2:07am UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233 "2019-09-09T02:07:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jigabytes](https://discourse.itk.org/user_avatar/discourse.itk.org/jigabytes/32/967_2.png) [@Jigabytes](https://discourse.itk.org/u/Jigabytes)\
**Post date:** [September 9, 2019, 2:07am UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/1 "2019-09-09T02:07:56Z")

</div>

Hi All,

I have a use case where given a 3D dicom image, I wish to apply for the filters only on selected slices. For example if 3D image has depth of 52 slices I want to apply Segmentation filters only from slice number 20 to slice number 30. How can I create an image out of these 10 slices so that I can apply Segmentation only on new image created out of these 10 slices image.

Thanks,  
Jiten

---

<div class="post-metadata">

**Author:** ![mattias](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/cab0a1/32.png) [@mattias](https://discourse.itk.org/u/mattias)\
**Post date:** [September 9, 2019, 7:08am UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/2 "2019-09-09T07:08:01Z")

</div>

Perhaps this will do the trick

[https://itk.org/Doxygen/html/classitk\_1\_1ExtractImageFilter.html](https://itk.org/Doxygen/html/classitk_1_1ExtractImageFilter.html)

or this

[https://itk.org/Doxygen/html/classitk\_1\_1RegionOfInterestImageFilter.html](https://itk.org/Doxygen/html/classitk_1_1RegionOfInterestImageFilter.html)

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [September 9, 2019, 1:10pm UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/3 "2019-09-09T13:10:52Z")

</div>

If you can identify to which files on disk do your slices of interest correspond to, you could copy only those slices into a new directory and open it as different image. This might, or might not be what you want to do.

---

<div class="post-metadata">

**Author:** ![Jigabytes](https://discourse.itk.org/user_avatar/discourse.itk.org/jigabytes/32/967_2.png) [@Jigabytes](https://discourse.itk.org/u/Jigabytes)\
**Post date:** [September 15, 2019, 3:24am UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/4 "2019-09-15T03:24:42Z")

</div>

Thanks this may work I will try it out and provide my findings and observation s!

---

<div class="post-metadata">

**Author:** ![Jigabytes](https://discourse.itk.org/user_avatar/discourse.itk.org/jigabytes/32/967_2.png) [@Jigabytes](https://discourse.itk.org/u/Jigabytes)\
**Post date:** [September 15, 2019, 3:25am UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/5 "2019-09-15T03:25:32Z")

</div>

Yup I would also need to save range of slices and a new image at later stage in post processing! Thanks

---

<div class="post-metadata">

**Author:** ![Jigabytes](https://discourse.itk.org/user_avatar/discourse.itk.org/jigabytes/32/967_2.png) [@Jigabytes](https://discourse.itk.org/u/Jigabytes)\
**Post date:** [September 29, 2019, 9:20pm UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/6 "2019-09-29T21:20:58Z")

</div>

Extract image filter does the trick!! Thanks much guys!!

---

<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:** [September 30, 2019, 1:43pm UTC](https://discourse.itk.org/t/how-to-process-only-few-slices-of-a-3d-dicom-image/2233/7 "2019-09-30T13:43:27Z")

</div>

In SimpleITK it’s really easy to extract a subset of an image using python’s array slicing.

For example, this is how you could extract slice # 20:

```
import SimpleITK as sitk
image1 = sitk.Image(100,100,100,sitk.sitkUInt8)
image2 = image1[20]

```

or if you want to extract a range of slices:

```
image3 = image1[20:30]
```
