extend line to the facing side of a border

조회 수: 4(최근 30일)
Walaa 2022년 11월 26일
댓글: Image Analyst 2022년 11월 26일
I measured and plotted the shortest distance between the two borders as a yellow line. How could I extend that line to the outer red line and measure its length? the code I used to calculate the shortest distance is attached.
%find all distance
D = sqrt((x1(:) - X2(:).').^2 + (y1(:) - Y2(:).').^2);
%find the minimum distance
minDistance = min(D(:));
% Find index of closest pair
[row, column] = find(D == minDistance);
smoothx1 = thisBoundary(:, 2);
smoothy1 = thisBoundary(:, 1);
smoothX2 = Boundary(:, 2);
smoothY2 = Boundary(:, 1);
for k = 1 : length(row)
% Report to command window.
index1 = row(k);
index2 = column(k);
xLine = [smoothx1(index1), smoothX2(index2)];
yLine = [smoothy1(index1), smoothY2(index2)];
plot( xLine, yLine, 'Color', 'y', 'LineWidth', 2);


Image Analyst
Image Analyst 2022년 11월 26일
I have no idea what you mean. The yellow line's endpoints are exactly on the red curves. What outer red line?
  댓글 수: 2
Image Analyst
Image Analyst 2022년 11월 26일
You know the yellow endpoints. So you know which one is on the outer red curve. You know both endpoints are so all you have to to is fit them to a line with polyfit. Then use polyval to extend the yellow line all the way across the image so you have yellow coordinates for every x value. Then use the distance formula like you did already to find the distances of every yellow point to every red point. Then take the two closest ones (the two distances that are the smallest). It's easy if you just think about it, right? What's so hard? If you could do the code you've already done, you can do this because it's not any more difficult.

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




Community Treasure Hunt

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

Start Hunting!

Translated by