Hello,

I have 2D matrix with greyscale image data, in particular point I have computed vector, which contains gradient in this point (via Sobel operator, it has 2 values - difference in x and in y axis), and I store this gradient vector like perpendicular vector to this gradient, so I have the vector, which says me the orientation of the edge in this point.

Now, what I want - I want to draw orientation of this edge in that particular point in my 2D image matrix like small line (for example 10 pixels) and I want to draw it in the way of this vector I have computed.

Any idea, how to do that?

Thanks for any help!

2
Contributors
1
2
Views
7 Years
Discussion Span
Last Post by spetro3387

Hello,

I have 2D matrix with greyscale image data, in particular point I have computed vector, which contains gradient in this point (via Sobel operator, it has 2 values - difference in x and in y axis), and I store this gradient vector like perpendicular vector to this gradient, so I have the vector, which says me the orientation of the edge in this point.

Now, what I want - I want to draw orientation of this edge in that particular point in my 2D image matrix like small line (for example 10 pixels) and I want to draw it in the way of this vector I have computed.

Any idea, how to do that?

Thanks for any help!

Well I am not exactly sure what you are trying to do, but i have worked with the sobel operator before in an edge detector. Assuming you know how to apply the x and y sobel operators to get the x and y gradient values (here they are Gx and Gy) then you can calculate the direction (theta) and magnitude of the gradient at every point. Here is a code snippet:

``````  /* Two theta condtions, need manual setting */
if(Gx == 0){
if(Gy == 0) //if Gx and Gy are zero, theta is zero
theta = 0;
else
theta = 90; // Gx is zero and Gy is non-zero, theta is 90
}
/* if not condition, calculate actual edge direction */
else{
theta = (atan2(Gy,Gx))*180/PI;
}

m_ppfGradientImage[y][x] = sqrt( ((Gx*Gx) + (Gy*Gy)) );
``````

So it sounds like you are trying to draw a 10 pixel line in a direction perpendicular to the gradient which I don't understand why, but all you would have to do is the following:

``````int X = column location of chosen point
int Y = row location of chosen point

for(int i = 1; i <= 10; i++){
x = X + ( cos( theta + (PI/2) ) * i );
y = Y - ( sin( theta + (PI/2) ) * i );
if( x and y are in bounds of array)