What method should you use to determine the direction of the gradient of pixels in an image?

I came across two methods for determining gradient values ​​and directions

1

I=imread('12.jpg');
I1=rgb2gray(I);
ed=edge(I1,'canny',0.4);
[gx gy]=gradient(double(ed),0.5);
figure;
imshow(I);
gm=sqrt(gx.^2+gy.^2);
gdp=atan2(gy,gx);
figure;
imshow(gm);
figure; imshow(gdp);

      

gm will keep the gradient magnitude and gdir direction

2: built-in matlab function

[gm gdp]=imgradient(ed);

      

Both outputs are completely different. Which one should you use to implement the stroke width conversion?

+3


source to share


1 answer


Although the original article did not specify which method to use, I found that two popular SWT implementations, DetectText and CCV, use the Sobel operator.

You get different outputs because you computed the gradient on the output of the Canny method (and not the Sobel on the input image, as it should be). Also imgradient

returns the orientation of the gradient in degrees, the atan2

result is in radians. You should use imgradient

to get magnitude and orientation, or imgradientxy

to get directional gradients if you want to compute orientation yourself.



For hints you can refer to this file or their technical report.

+1


source







All Articles