2

I am using The sobel operator to detect edges in a grayscale image with EmguCV 3.0 (the .NET Wrapper for OpenCV).

The code I am using is

Image<Gray, byte> gray = new Image<Gray, byte>(@"C:\gray.bmp");
Image<Gray, float> sobel = gray.Sobel(0, 1, 3).Add(gray.Sobel(1, 0, 3)).AbsDiff(new Gray(0.0));

This is the preprocessed image (gray)

And this is what I get out (sobel)

As you can see, the edges in the top-right and the bottom-left corner are very weak. I first thought, it could have something to do with the original image, so I rotated it by 180 degrees and ran the sobel-filter again. The result still has very weak edges in the top-right and the bottom-left corner (unfortunately I am not allowed to post more than two links here, so I can´t show it to you).

So My question is: Is this a bug, or am I using the sobel filter wrong? Should´t it be rotation-invariant, when ran in two dimensions? And how can I fix it, to see these two edges as strong as the other ones?

Dmitry
  • 13,797
  • 6
  • 32
  • 48
derjan
  • 41
  • 2
  • The sobel-operator, applied to the rotated image: http://i.stack.imgur.com/U7QCF.jpg (still weak edges in the top-right and the bottom-left corner) – derjan Aug 14 '15 at 11:33
  • Why not make your own filter? http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.html – LovaBill Aug 14 '15 at 11:38

1 Answers1

2

I am sorry, I have already found a solution: The code I now use is:

Image<Gray, float> sobel = 
    gray.Sobel(1, 0, 3).AbsDiff(new Gray(0.0))
        .Add(gray.Sobel(0, 1, 3).AbsDiff(new Gray(0.0)));

This approximates the norm by |Gxy| = |Gx| + |Gy|, and the result is a good image with nice clean edges: https://i.stack.imgur.com/COJSG.png

derjan
  • 41
  • 2