0

I want to apply a 3x3 or larger image filter (gaussian or median) on a 2-d array.

Though there are several ways for doing that such as scipy.ndimage.gaussian_filter or applying a loop, I want to know if there is a way to apply a 3x3 or larger filter on each pixel of a mxn array simultaneously, because it would save a lot of time bypassing loops. Can functional programming be used for the purpose??

There is a module called scipy.ndimage.filters.convolve, please tell whether it is able to perform simultaneous operations.

1
  • 1
    ... The only way you can do this "simultaneously" is with mxn separate processor cores. How else do you propose to get all these instructions processed at exactly the same time? Maybe I'm not understanding your question. Oct 19, 2012 at 6:34

2 Answers 2

2

You may want to learn about parallel processing in Python: http://wiki.python.org/moin/ParallelProcessing or the multiprocessing package in particular: http://docs.python.org/library/multiprocessing.html

Check out using the Python Imaging Library (PIL) on multiprocessors. Using multiprocessing with the PIL and similar questions.

You could create four workers, divide your image in four, and assign each quadrant to a worker. You will likely lose time for the overhead however. If, on another hand, you have several images to process, then this approach may work (letting each worker opening its own image).

1

Even if python did provide functionality to apply an operation to an NxM array without looping over it, the operation would still not be executed simultaneously in the background since the amount of instructions a CPU can handle per cycle is limited and thus no time could be saved. For your use case this might even be counterproductive since the fields in your arrays proably have dependencies and if you don't know in what order they are accessed this will most likely end up in a mess.

Hugues provided some useful links about parallel processing in Python, but be careful when accessing the same data structure such as an array with multiple threads at the same time. If you don't synchronize the threads they might access the same part of the array at the same time and mess things up.
And be aware, the amount of threads that can effectively be run in parallel is limited by the number of processor cores.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.