# Is there a subset and combine filter?

**URL:** <https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212>\
**Category:** Beginner Questions\
**Created:** [July 23, 2022, 1:55am UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212 "2022-07-23T01:55:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chlee](https://discourse.itk.org/user_avatar/discourse.itk.org/chlee/32/3788_2.png) [@chlee](https://discourse.itk.org/u/chlee)\
**Post date:** [July 23, 2022, 1:55am UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212/1 "2022-07-23T01:55:34Z")

</div>

Hi,

I very much appreciate for any tips, just started using the ITK. Not to re-invent the wheel, may I ask whether there are any filters that subset a 3D image along slices (say take z=5-10), process through filters, and then combine them back together?

Specifically, I want to process one part of my z-stacks (say superficial, that is clearly saturated) with one particular filter, and the other (not saturated) with another. I learned to use SliceBySliceImageFilter, so if there is a subset + combine filter it could easily processed as a pipeline.

Thank you very much for any suggestions!

---

<div class="post-metadata">

**Author:** ![chlee](https://discourse.itk.org/user_avatar/discourse.itk.org/chlee/32/3788_2.png) [@chlee](https://discourse.itk.org/u/chlee)\
**Post date:** [July 23, 2022, 2:53am UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212/2 "2022-07-23T02:53:30Z")

</div>

I realize that ExtractImageFilter + [TileImageFilter](https://examples.itk.org/src/filtering/imagegrid/appendtwo3dvolumes/documentation) might do, will work on this!

---

<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 25, 2022, 5:00pm UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212/3 "2022-07-25T17:00:24Z")

</div>

Using the array slicing feature of SimpleITK makes this really easy. Here’s an example I cooked up:

```
import SimpleITK as sitk

img = sitk.Image([100,100,30], sitk.sitkUInt8)

img1 = img[:, :, 0:10]
img2 = img[:, :, 10:20]
img3 = img[:, :, 20:30]

# make middle sub-vol grey
img2 = img2 + 100

out = sitk.Tile([img1, img2, img3], [1, 1, 0])

```

I split the original image into thirds using array slicing, and then put the parts back together with the Tile function (as you said).

---

<div class="post-metadata">

**Author:** ![chlee](https://discourse.itk.org/user_avatar/discourse.itk.org/chlee/32/3788_2.png) [@chlee](https://discourse.itk.org/u/chlee)\
**Post date:** [July 25, 2022, 9:50pm UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212/4 "2022-07-25T21:50:41Z")

</div>

Thank you so much @dchen ! I see that many examples are written both in Python and C++. As a beginner of using ITK, I am wondering whether Python is good enough to do image processing at the moment - I can also write python scripts but I have relatively large 3D images (and many) and wonder what the speed benchmark between the two approaches might be.

---

<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 26, 2022, 2:28pm UTC](https://discourse.itk.org/t/is-there-a-subset-and-combine-filter/5212/5 "2022-07-26T14:28:10Z")

</div>

These days I do everything in Python. It’s just so much easier and quicker to code something up and try it out in Python.

If you just use ITK filters to do your image manipulations or computations there should be no performance difference between C++ and Python, since the Python code is just making calls to the underlying C++ ITK library.

If you have to implement your own filter, or do something like iterate through all the pixels in an image, then you’ll have to go to C++.
