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

あなたが探しているのはおそらくSobel Operatorです。これは、行列を使用してピクセルの周囲の近傍の畳み込みとして実装されます。

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

そして再び:

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

2 つの畳み込み x と y の結果をそれぞれ呼び出します。それらを取得したら、二乗和の平方根をとることで勾配の大きさを取得できます。

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

x 上の y の逆正接を取ることによるグラデーションの方向 (調べているピクセルに正接する必要があります):

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