Filter löschen
Filter löschen

extend line to the facing side of a border

3 Ansichten (letzte 30 Tage)
Walaa
Walaa am 26 Nov. 2022
Kommentiert: Image Analyst am 26 Nov. 2022
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

Antworten (1)

Image Analyst
Image Analyst am 26 Nov. 2022
I have no idea what you mean. The yellow line's endpoints are exactly on the red curves. What outer red line?
  2 Kommentare
Walaa
Walaa am 26 Nov. 2022
I mean to extend both ends of the yellow line to the outer border. like this
Image Analyst
Image Analyst am 26 Nov. 2022
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by