Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I have an image by Sobel mask, and I want to calculate 'gradient energy'.

I was trying to using this code:

C++
int w = 474;
int h = 477;
int sum=0;
BYTE *ptr; //byte array of image data.

//...

for (int j=0; j<h; j++)
    for (int i=0; i<w; i++)
        sum += ptr[w*j+i];


But this code is so slow. (if image size is big)

So I'm trying to use SSE Operators.

C++
__m128i energy;
__m128i current_1; // image data

//...
for (int j=0; j<h; j++)
{
    for (int i=0; i<w; i+=8)
    {
     //...
        energy = _mm_add_epi8(energy,current_1);
     //...
    }
}


But it happend overflow ..

How can I avoid overflow and calculate gradient energy?

Thank you :)

What I have tried:

I tried to use code as above. But it happned overflow in __m128i.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900