Which method should I use to find gradient direction of pixels in an image?

2k views Asked by At

I came across two methods of finding gradient magnitudes and direction

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 store gradient magnitude and gdir the direction

2: An inbuilt matlab function

[gm gdp]=imgradient(ed);

Both the outputs are entirely different. Which one should I use for implementation of Stroke Width Transform?

1

There are 1 answers

0
majkel.mk On

Although the original paper doesn't state which method should be used, I found that in two popular implementations of SWT: DetectText and CCV Sobel operator is utilized.

You are getting different outputs because you computed gradient on Canny's method output (not Sobel on input image, as it should be done). Also imgradient returns gradient orientation in degrees, atan2 result is in radians. You should use imgradient to get magnitude and orientation or imgradientxy to get the directional gradients if you want compute orientation yourself.

For clues, you could refer to this file or their technical report.