jlm47
jlm47

Reputation: 43

FastCV Erode/Dilate Parameters

I'm using both OpenCV and FastCV on an android device to perform some image processing operations. After thresholding a frame, I am left with a binary image with moderate amounts of both black and white noise present near the region of interest.

Performing erosion, followed by dilation over the image gives me a virtually noise free image that can be used for further processing, however both of the above libraries have their downfalls.

OpenCV

Mat element = getStructuringElement(MORPH_RECT, Size(2 * erosionSize + 1, 2 * erosionSize + 1), Point(erosionSize, erosionSize));
erode(in, in, element);
element.release();

Forgive my magic numbers, but my simple invocation of OpenCV's erode/dilate looks like the above. I can then modify the erosionSize/dilationSize parameters of this in order to adjust how aggressive the function is at eliminating noise. The problem? Performance is of the utmost priority here and this function runs rather slower than I would like.

FastCV

fcvFilterErode3x3u8_v2 (const uint8_t *__restrict src, unsigned int srcWidth, unsigned int srcHeight, unsigned int srcStride, uint8_t *__restrict dst, unsigned int dstStride)

The above prototpye is for FastCV's erode implementation, where there is no parameter to tune the size of the erosion. Given that FastCV has been optimized for mobile architectures, and that I suspect it actually makes use of the GPU present in the Galaxy Nexus I am using for testing, this function is much faster than the above. However I need to loop and run it over the same frame multiple times to achieve the same level of erosion, sacrificing any performance benefit in the process.

Is anyone aware of either:

Upvotes: 2

Views: 2400

Answers (1)

Thibauld Nion
Thibauld Nion

Reputation: 409

If your intention is to systematically perfom both operations (erosion and dilation) successively, and if you're ok with using the same parameter size for both, then you might want to try applying an opening with opencv's dedicated function:

http://docs.opencv.org/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html

Mathematically this is equivalent to performing and erosion and then a dilation, but there are optimized implementations of the opening that can do it much quicker that by applying both operations successively.

Disclaimer: I haven't checked opencv's implementation for those operation, but you'll want to give a try -- if you haven't done it already of course.

Upvotes: 3

Related Questions