使用NEON减去两个图像

时间:2013-03-18 16:24:27

标签: arm neon intrinsics

我试图通过使用Neon内在函数作为练习来减去两个图像(灰度),我不知道使用C内在函数减去两个向量的最佳方法是什么。

void subtractTwoImagesNeonOnePass( uint8_t *src, uint8_t*dest, uint8_t*result, int srcWidth)
{


    for (int i = 0; i<srcWidth; i++)
    {
        // load 8 pixels
        uint8x8x3_t srcPixels  = vld3_u8 (src);
        uint8x8x3_t dstPixels  = vld3_u8 (src);
        // subtract them
        uint8x8x3_t subPixels =  vsub_u8(srcPixels, dstPixels);
        // store the result
        vst1_u8 (result, subPixels);
        // move 8 pixels
        src+=8;
        dest+=8;
        result+=8;

    }

}

1 个答案:

答案 0 :(得分:3)

看起来你正在使用错误的负载和存储。你是否从三个频道的例子中复制了这个?我认为这就是你所需要的:

#include <stdint.h>
#include <arm_neon.h>

void subtractTwoImagesNeon( uint8_t *src, uint8_t*dst, uint8_t*result, int srcWidth, int srcHeight)
{
    for (int i = 0; i<(srcWidth/8); i++)
    {
        // load 8 pixels
        uint8x8_t srcPixels = vld1_u8(src);
        uint8x8_t dstPixels = vld1_u8(dst);
        // subtract them
        uint8x8_t subPixels = vsub_u8(srcPixels, dstPixels);
        // store the result
        vst1_u8 (result, subPixels);
        // move 8 pixels
        src+=8;
        dst+=8;
        result+=8;
    }
}

你还应该检查srcWidth是8的倍数。另外,你需要包含图像的所有行,因为看起来你的代码只处理第一行(也许你知道这一点并且只是减少了简单的例子。)