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!

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;
  }

  /* Calculate gradient magnitude */
  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)
    m_ppfGradientImage[y][x] = 255;
}

the PI/2 would give you the angle perpendicular to the gradient direction. Up to you to add or subtract PI/2 (there are two perpendicular angles, to the right and to the left).

Hope this helps.

Sam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.