开发者

Sobel Edge Detection, edge orientation

开发者 https://www.devze.com 2023-04-05 02:52 出处:网络
I\'ve implemented a Sobel Edge Detector and had some questions about computing edge orientations. I\'m using this function to compute edge intensities after ha开发者_JS百科ving done the sobel kernel

I've implemented a Sobel Edge Detector and had some questions about computing edge orientations.

I'm using this function to compute edge intensities after ha开发者_JS百科ving done the sobel kernel convolution.

Gxy = sqrt( pow(Gx, 2) + pow(Gy,2) )

Where Gx is sum of the convolution for the sobel kernel in the X direction and Gy is sum of the convolution for the sobel kernel in the Y direction. (note the sobel kernel in the X and Y direction are different kernels)

Y kernel:

  • 1 2 1
  • 0 0 0
  • -1 -2 -1

X kernel:

  • -1 0 1
  • -2 0 2
  • -1 0 1

when I try to compute the edge orientation (theta is in degrees), I'm using the following rules:

  • if Gy == 0 and Gx == 0, then theta = 0
  • if Gy != 0 and Gx == 0, then theta = 90
  • otherwise, theta = (arctan( Gy / Gx ) * 180) / PI

all my documentation is telling me the angles should be > 0 and < 360 and I continue to get edges with negative value orientations. Is there something I'm doing incorrectly when computing theta or my convolution? Or should i just add 360 or 180 to negative theta values?

thanks in advance,


It's hard to answer your question precisely because you haven't mentioned exactly how you calculate the arctan function.

For example, if you're using the standard library's atan function, then negative angles are to be expected.

Furthermore, you'll notice that atan with a single argument can only ever return values in the first and fourth quadrants (because, for example, tan 45 == tan 225 when using degrees).

If you really want an angle in one of the four quadrants (you should really ask yourself if this matters for your application), then have a look at atan2.


If you are using OpenCV, C++ you could do the following:

    Mat gray = some grayscale image;

Calculate edge gradients in x/y axis'

    Mat dx(gray.rows, gray.cols, CV_16SC1);
    Mat dy(gray.rows, gray.cols, CV_16SC1);
    int aperture_size=3;
    Sobel(gray, dx, CV_32FC1, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
    Sobel(gray, dy, CV_32FC1, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);

Calculate the angle and magnitude using OpenCV's cartToPolar

    Mat Mag(gray.size(), CV_32FC1);
    Mat Angle(gray.size(), CV_32FC1);
    cartToPolar(dx, dy, Mag, Angle, true);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号