possible NaN gradient direction on canny edge detector - image processing on matlab

image-processing, matlab

Solution

I think it actually doesnt' matter what value you give to theta, as a Gx and Gy equal to zero means that there is no gradient, meaning there is no edge. That pixel has no edges, so it has not either an angle of direction of the edge. detect when Gy=gx=0 and write in theta whathever you want.

Oh! but dont forget that arctan(Inf)=pi/2! If only the value of Gx is zero remember that you have a result!

EDIT: In the image all the black areas have not gradient, thus have not angle.

Problem

I'm writing my own version of Canny's edge detection algorithm. My question is, how can I compute the direction of gradient? I already know that: But what should I do when Gy = Gx = 0?

Original source