Is there a subset and combine filter?


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!

I realize that ExtractImageFilter + TileImageFilter might do, will work on this!

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

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.

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++.

1 Like