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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1208588/image.png)
%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
0 个评论
回答(1 个)
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
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 Center 和 File Exchange 中查找有关 Modify Image Colors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!