Find pixels at given distance along line

조회 수: 1 (최근 30일)
Mariana
Mariana 2014년 5월 1일
댓글: Image Analyst 2014년 5월 3일
Hello, as you can see on image attached I´ve computed perpendicular lines to red lines. I know the slope of red line, the slope of green line and I know the coordinates of the cross-section also. So I computed x and y coordinates of the green line as follows:
slope = (r1 - r2) / (s1 - s2); %red line slope
slRec = -1 / slope; %perpendicular green line slope
ym = (y1 + y2)/2; xm = (x1 + x2)/2; %cross-section point
according to well known line equation y = ax + b I´ve counted y when x was created as:
b = ym - a*xm;
length = 5;
y = ym - length : 0.25 : ym + length;
x = (y - b) / a;
coordinates = ([y; x])';
But as you can see on my image, there is problem that when the length of the line is given by y-axis range it is different length itself. How can I find pixel value at unit distance from the red line (and along green line)?

답변 (1개)

Image Analyst
Image Analyst 2014년 5월 1일
I've done this successfully before. What you need to do, so that the cross sectional line doesn't wildly waver all over the place is to take several points along the red line, not just 2. Then use polyfit() to fit a line or quadratic. (The line is easy. Using a quadratic of cubic is also easy but requires calculus.) Then compute your perpendicular line assuming some fixed length, like 30 pixels or whatever.
  댓글 수: 4
Mariana
Mariana 2014년 5월 3일
ok. actually I don´t use length for name of variable in my code, because I´m not english speaking and I changed only for the question purpose. My delta x not fixed is the problem I´m trying to solve. I´d be happiest if the length of green line would be such that it touches the object border. Thank you for all your answers.
Image Analyst
Image Analyst 2014년 5월 3일
I've started working on a general purpose demo but it's not done yet.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by