Menu

Feature proposal - image difference with offset

2017-07-28
2017-07-28
  • Nikolai Vorontsov

    Hello Ihar,

    sometimes you need not only to calculate the summary difference between two images, but also get (visualize) this difference.

    Here is a ready SSE2 code snippet for the following transform:

    byte out[8] = word image[8] - word previousImage[8] + fixed_offset

    The difference can be small or even negative, so a fixed offset value is added. All calculation is done in 16-bit unsigned word values, saturated back to 8-bit unsigned result.

    m128i ofs = _mm_set1_epi16(offset);
    m128i zero = _mm_set1_epi8(0);

    for each 16 bytes in line:
    m128i v1a = _mm_loadu_si128(image_line);
    m128i v1b = _mm_unpacklo_epi8(v1a, zero); // 16-bit high and low parts
    v1a = _mm_unpackhi_epi8(v1a, zero);

    m128i v2a = _mm_loadu_si128(previousImage_line); // Same for another image line
    m128i v2b = _mm_unpacklo_epi8(v2a, zero);
    v2a = _mm_unpackhi_epi8(v2a, zero);

    v1b = _mm_sub_epi16(_mm_add_epi16(v1b, ofs), v2b); // Add offset first, subtract ref.image
    v1a = _mm_sub_epi16(_mm_add_epi16(v1a, ofs), v2a);

    v1a = _mm_packus_epi16(v1b, v1a); // Contert to 8-bit with saturation

    _mm_storeu_si128(result_line, v1a);

    Feel free to use it if you decide to add that kind of algo to your lib.

    Nikolai

     
    • Yermalayeu Ihar

      Yermalayeu Ihar - 2017-08-01

      Hello, Nikolai!

      It would be better if you add this code yourself. Join to the development of Simd Library at GitHub. If you have the wish I will give more information how to do this.

      Ihar.

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.