Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Maybe you can reduce the time by applying less iterations but with a larger structuring element, since the effect is the same ( see also http://answers.opencv.org/question/6240/equivalence-between-structural-elements/. Note that (if I interprete the code correctly) this optimization is already done in OpenCV, however only if the kernel has no zero-elements ( see imgproc/src/morph.cpp l.1165 - OpenCV.2.4.4).

To answer your questions: Yes, it should be possible to parallelize them, since every morphological operation is applied on a block of the image (Note again that this is (partially) already done in OpenCV if you have TBB and TEGRA_OPTIMIZATION.). Thus, maybe you can divide your image in overlapping blocks and apply the morphological operation on each block in parallel.

For the parallelization I suggest to use OpenCV's parallel_for_ ( see http://answers.opencv.org/question/3730/how-to-use-parallel_for/ for the usage) which afaik internally uses TBB. TBB is a C++ library for parallelization and yes you need to implement your code in a slight different way, but the rest works completely automatic (see http://threadingbuildingblocks.org to learn more about TBB).

Good luck for your project!