Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
DISTANCE PIXEL ON A straight line

Subject: DISTANCE PIXEL ON A straight line

From: CRIS

Date: 3 May, 2012 14:02:07

Message: 1 of 6

Hi, i have an image where i find a straight line ( i have the coefficients of this line y =ax+b). I must to find a pixel in the same image (only one pixel) that lies in this straight line and that is at distance 'd' from another pixel in the image (also this pixel lies in the straight line).
Any suggestions to do this in a simple and fast way?
thanks.

Subject: DISTANCE PIXEL ON A straight line

From: Matt J

Date: 3 May, 2012 14:27:17

Message: 2 of 6

"CRIS" wrote in message <jnu34v$f3l$1@newscl01ah.mathworks.com>...
> Hi, i have an image where i find a straight line ( i have the coefficients of this line y =ax+b). I must to find a pixel in the same image (only one pixel) that lies in this straight line and that is at distance 'd' from another pixel in the image (also this pixel lies in the straight line).
> Any suggestions to do this in a simple and fast way?


No pixel will lie exactly on a general line y=ax+b.
What approximation rule do you intend to use to decide whether the pixel is "close enough" to the line?

Subject: DISTANCE PIXEL ON A straight line

From: CRIS

Date: 3 May, 2012 14:58:17

Message: 3 of 6

"Matt J" wrote in message <jnu4k5$md9$1@newscl01ah.mathworks.com>...
> "CRIS" wrote in message <jnu34v$f3l$1@newscl01ah.mathworks.com>...
> > Hi, i have an image where i find a straight line ( i have the coefficients of this line y =ax+b). I must to find a pixel in the same image (only one pixel) that lies in this straight line and that is at distance 'd' from another pixel in the image (also this pixel lies in the straight line).
> > Any suggestions to do this in a simple and fast way?
>
>
> No pixel will lie exactly on a general line y=ax+b.
> What approximation rule do you intend to use to decide whether the pixel is "close enough" to the line?

yes i think that a pixel not lie exactly on a line, i I don't know, what do you recommend to me ?

Subject: DISTANCE PIXEL ON A straight line

From: Matt J

Date: 3 May, 2012 15:21:24

Message: 4 of 6

"CRIS" wrote in message <jnu6e9$1ln$1@newscl01ah.mathworks.com>...
>
> > No pixel will lie exactly on a general line y=ax+b.
> > What approximation rule do you intend to use to decide whether the pixel is "close enough" to the line?
>
> yes i think that a pixel not lie exactly on a line, i I don't know, what do you recommend to me ?
============

I have no basis for making a recommendation. You haven't described the application, yet.

Subject: DISTANCE PIXEL ON A straight line

From: Roger Stafford

Date: 3 May, 2012 17:04:21

Message: 5 of 6

"CRIS" wrote in message <jnu34v$f3l$1@newscl01ah.mathworks.com>...
> Hi, i have an image where i find a straight line ( i have the coefficients of this line y =ax+b). I must to find a pixel in the same image (only one pixel) that lies in this straight line and that is at distance 'd' from another pixel in the image (also this pixel lies in the straight line).
> Any suggestions to do this in a simple and fast way?
> thanks.
- - - - - - - - - -
  What if your line were vertical? The equation y = a*x+b wouldn't apply in that case. You can always characterize a line as containing two given points P1 = (x1,y1) and P2 = (x2,y2). Any point P = (x,y) on the line through them satisfies the equation

 P = (1-t)*P1 + t*P2

where t is an appropriate real parameter.

  Thus if P is to be a distance d from P1 you get

 d^2 = (x-x1)^2 + (y-y1)^2 = t^2*((x2-x1)^2+(y2-y1)^2)

and therefore

 t = + or - d/sqrt((x2-x1)^2+(y2-y1)^2)

Solving for x and y gives you two possible pixel positions. If x and y aren't valid pixel indices, round them.

Roger Stafford

Subject: DISTANCE PIXEL ON A straight line

From: CRIS

Date: 4 May, 2012 07:10:16

Message: 6 of 6

Great idea Roger, thak you.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us