Python filter example

(Julien Finet) #1


I would like to write an ITK filter in Python. Is there an example somewhere ?


(Bradley Lowekamp) #2

Hello Julien,

There are many types of filters. Are you looking to write a composite filter composed of other ITK filters and you logic? Integrate other algorithms into an ITK pipeline?

If you are interested in doing operations on each pixel, visiting each pixel with an iterator is generally not efficient. If you are able to figure out how to do the operations with filter on the whole image at a time , similar to numpy broadcast operations the implementation can be efficient.

(Julien Finet) #3

Thank you Bradley,

I would like (for now) to create a composite filter (composed of other ITK filters).
For example, I would need to overwrite the GenerateInputRequestedRegion function.


(Francois Budin) #4

Hello @finetjul,

Are you trying to compose existing ITK filters or use some filters and add custom steps at some point in the processing? If you are simply trying to compose filters together, I suggest you take a look at the ITK Python pipeline class for which I wrote an example here. Note that you may already have tried that since I wrote this example as an reply to one of your questions.
If you need to add custom steps in your processing, you could try to still use this class but combine it with an ITK Python templated_class object.
If you are looking at actually fully writing a filter from scratch in Python, I cannot think of a good example right now, but if I think of one, I will add it here.