distance line from a point

Hi all, lets say i have a binary image, and i want to find the distance of a line (the one with the blue) from my mesh which is pictured in the above image.
The red points are the "aces" on the image. The values with 1 in my binary image
Any help?

Answers (1)

But you already have those pixels/points:
n = 100; % number of pixels
x0 = round( linspace(min(x),max(x),n) ); % coordinates/columns of points/pixels
y0 = round( linspace(min(y),max(y),n) ); % coordinates/rows of points/pixels
Please look at the picture, because i did my best
Untitled.png
Perpendicular vector p:
Then use equation of a line from two points:
- line from x and x0
- line from x and x1
We have to find x,y then distance:
Accept the answer please if i helped you

5 Comments

Hi , i have a question :
I have an array lets say (120x2) with the points on the line.
Why are you using min and max in the linespace function?
x,y are given coordinates of a point, for exaple lets say a point on my line is (1,26) -->max(1)=1 and min(1)=1, the same with y=26.
Whats the purpose of min,max?
I lied to you on the first picture. (x1,y1) and (x2,y2) are first and last points
I used min() and max() to indicate first and last points and build a line
img.png img1.png
Above code can be written as:
x1 = min(x);
x2 = max(x);
y1 = min(y);
y2 = max(y);
n = 100;
x0 = linspace(x1,x2,n);
x0 = round(x0); % rounding because pixels position must be integer
y0 = linspace(y1,y2,n);
y0 = round(y0);
pasta pontikaki
pasta pontikaki on 11 May 2019
Edited: pasta pontikaki on 11 May 2019
Hi, all those you wrote above help me, but i have one more question:
lets say my starting point is x1,y1=(1,26) and my ending point x2,y2=(120,90)
you choose random points in the linespace for x0 from 1..120 and fro y0=26...90
After you chose those points you create two new vectors x0,y0 with coordinates that they represent a new line.
But, i want to find the closest points to my line. Is it clear?
Firstly the quantity of elements in x space is 1:120 =120 elements, and on y spance 26:90 =64 elments, so i have two unequal vector for my new line x0,y0.
Secondly in the image the pointed pixel with the red arrow (A1) is not detected due to the fact the linespace function choose random (100) pixel in the space from 1 to 120. Also in A2 arrow the pixel which is detected is not the closest one. The pixel with the cyan circle is the one that is picked.
Any help how to choose the closest pixel all over my line?
You are right
Can you please unaccept my answer so other peaple can help you?

Sign in to comment.

Categories

Asked:

on 8 May 2019

Commented:

on 11 May 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!