During coding some pixel manipulation class, I have implemented non max suppression function.
Code is here:
signed char * nonMaxSuppress(int windowSize, signed char * pointer) {
int delta = windowSize / 2;
int index;
int counter = 0;
signed char current;
for(int row = 3; row < GLOBAL_HEIGHT - 3; ++row)
{
for(int col = 3; col < GLOBAL_WIDTH - 3; ++col)
{
counter = 0;
current = pointer[(row * GLOBAL_WIDTH) + col];
for(int i = 0; i < windowSize; ++i)
{
for(int j = 0; j < windowSize; ++j)
{
index = ((row - delta + i) * GLOBAL_WIDTH) + (col - delta + j);
if(current > pointer[index]) {
counter++;
}
}
}
if(counter != ((windowSize * windowSize) - 1)){
pointer[(row * GLOBAL_WIDTH) + col] = 0;
}
}
}
return pointer;}
Now the resulting picture before and after non max suppression is quite weird. It feels like some line started to appear out of the blue. Please watch attached pictures (Before and After non max suppression).
I will be thankful in case of any help.
Thx!
Please ignore the 3 pixels error i have in the edge of the images and just for you knowledge those image after grayscale and Diffrence Of Gaussian
Can you see the added lines? What is it?
You are trying to perform the suppression inplace. Consider the pixel (col, row). Once you modify its contents the next pixel (col+1, row) will have a different windowSize*windowSize neighbourhood.
To fix this problem you have to use another array as an output. Just replace
if(counter != ((windowSize * windowSize) - 1)){
pointer[(row * GLOBAL_WIDTH) + col] = 0;
}
with
output[(row * GLOBAL_WIDTH) + col] =
(counter != ((windowSize * windowSize) - 1)) ? 0 : current;