0

我想在图像中的每个像素处找到切线。注意:图像具有白色背景,形状边框颜色为块状。

我所做的是,阿尔戈

While(true)
     take pixel 
     if pixel color is black 
           make 3 X 3 matrix => fill the matrix by surrounding pixel color
            ...means assume white =0 and black=1 then keeping selected pixel 
           at center for 3 X 3 matrix and finding all other value;
           ----------------------------here i want to find tangent line to selected pixel;
     end if
     Move to next pixel.
End  while 

请帮助头上的考试。

4

1 回答 1

0

What you're looking for is probably a Sobel Operator. It's implemented as a convolution of the neighborhood around a pixel with the matrix:

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

and again with:

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

Call the results of the 2 convolutions x and y, respectively. Once you have them, you can get the magnitude of the gradient by taking the square root of the sum of the squares:

mag = sqrt(x * x + y * y);

and the direction of the gradient (which should be tangent to the pixel you're examining) by taking the arctangent of y over x:

tangent = atan2(y / x)
于 2012-11-04T06:13:56.600 回答