Subtracting two images using NEON

怎甘沉沦 提交于 2020-03-22 10:35:39

问题


I'm trying to subtract two images(grayscaled) by using Neon intrinsics as an exercise, I don't know what is the best way to subtract two vectors using the C intrinsics.

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:


It looks like you're using the wrong kind of loads and stores. Did you copy this from a three channel example? I think this is what you need:

#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;
    }
}

You should also check that srcWidth is a multiple of 8. Also, you'd need to include all the lines of the image, as it appears that your code only handles the first line (maybe you know this and just cut down the example for simplicity).



来源:https://stackoverflow.com/questions/15481839/subtracting-two-images-using-neon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!