1

Can someone tell me a fast function to find the gaussian blur of an image using a 5x5 mask. I need it for iOS app dev. I am working directly on the memory of the image defined as

unsigned char *image_sqr_Baseaaddr = (unsigned char *) malloc(noOfPixels);

for (row = 2; row < H-2; row++) 
{
    for (col = 2; col < W-2; col++) 
    {
        newPixel = 0;
        for (rowOffset=-2; rowOffset<=2; rowOffset++)
        {
            for (colOffset=-2; colOffset<=2; colOffset++) 
            {
                rowTotal = row + rowOffset;
                colTotal = col + colOffset;
                iOffset = (unsigned long)(rowTotal*W + colTotal);
                newPixel += (*(imgData + iOffset)) * gaussianMask[2 + rowOffset][2 + colOffset];
            }
        }
        i = (unsigned long)(row*W + col);
        *(imgData + i) = newPixel / 159;
    }
}

This is obviously the slowest function possible. I heard that ARM Neon intrinsics on the iOS can be used to make several operations in 1 cycle. Maybe that's the way to go ?

The problem is that I am not very familiar and don't have enough time to learn assembly language at the moment. So it would be great if anyone can post a Neon intrinsics code for the problem mentioned above or any other fast implementation in C/C++.

4

2 に答える 2

6

NEONを使用したSIMD最適化に入る前に、まずスカラーの実装を改善する必要があります。現状のコードの最大の問題は、ガウスカーネルが分離可能であるのに対し、分離不可能なフィルターであるかのように実装されていることです。分離可能な実装に切り替えることで、N ^ 2から2Nまでの操作の数を減らすことができます。これは、5x5カーネルの場合、25の乗算から10に削減されます。つまり、わずかな労力で2.5倍の速度が得られます。

十分に最適化されたスカラー実装は、SIMDに頼る必要なしにあなたのニーズを満たすかもしれません。そうでない場合は、少なくともこれらのスカラー最適化をベクトル化された実装に引き継ぐことができます。


http://en.wikipedia.org/wiki/Gaussian_blur

http://blogs.mathworks.com/steve/2006/11/28/separable-convolution-part-2/

于 2012-02-06T11:00:39.037 に答える
4
  1. Separate your kernel, as described by Paul R.
  2. Don't re-invent the wheel. Use vImage, which is part of the Accelerate framework, and implements a vectorized, multi-threaded convolution for you. Specifically, it seems like you want the function vImageConvolve_Planar8.
于 2012-02-06T18:18:04.010 に答える