# Thread: Image processing - Sobel filter problem (edge detection)

1. ## Image processing - Sobel filter problem (edge detection)

Hi everyone,

I'm trying to perform edge detection on a bitmap I get from the camera viewfinder, using a simple sobel operator. It's quite a straight forward task, but somehow the result doesn't look like expected (something like this for the x/y gradients: http://www.dca.fee.unicamp.br/dipcou...-sobel-x-y.gif )

This is my code (both bitmaps are EGray256):
Code:
```
iGrayBitmap->LockHeap(ETrue);
iGrayBitmap->UnlockHeap(ETrue);

TInt x=0, y=0, i=0, dx=0, dy=0;

for(i=0; i<w*h; i++)
{
// if we're at the first column - first pixel of a row:
// increment rows x and reset columns y
if (i==(y+1)*w) { y++; x=0; }
// else increment columns
else { x++; }

// if we're not in the first column or the first/last row (image boundaries)
// apply Sobel filter
if(x!=0 && x!=w-2 && y!=0 && y!=h-2 )
{
dx = gImg[i-w-1] + gImg[i-w+1] + gImg[i-w]*2 - gImg[i+w-1] - gImg[i+w+1] - 2*gImg[i+w];

dy = gImg[i-w-1] + gImg[i+w-1] + gImg[i-1]*2 - gImg[i-w+1] - gImg[i-w+1] - 2*gImg[i+1];

proImg[i] = dx;

}
else
{
proImg[i] = 255;
}

}```
As you can see here, the edges are detected, but where does all the white noise come from? Shouldn't it be just plain gray? (the test image is a white triangle on a light gray background, the screenshot is from the horizontal gradient)
http://tinypic.com/r/dpg1gh/3
Original image:
http://tinypic.com/r/11r7h37/3

Does anybody see what might be the problem?

Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•