extend line to the facing side of a border

3 次查看(过去 30 天)
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);
end

回答(1 个)

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 个评论
Walaa
Walaa 2022-11-26
I mean to extend both ends of the yellow line to the outer border. like this
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Modify Image Colors 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by