change the color of line inside the boundaries and measure length of this part of line?

4 views (last 30 days)
Could you kindly help me in changing the colour of the line inside the red borders to green and measuring the length of this part of  line? I attached the code for plotting the cyan line.
% Plot the boundary over the original image
% Display the image.
subplot(1,2, 2);
imshow(originalImage2, []);
hold on;
caption = sprintf('original image with plotted disc diameter');
title(caption, 'FontSize', 10);
hold on
plot(smoothX1, smoothY1, 'r-', 'LineWidth', 4);
plot(smoothX2, smoothY2, 'r-', 'LineWidth',4);
hold on
%-------------------------------------------------------------------------------------------------------------------------------------
xLine = [smoothx1(index1), smoothX2(index2)];
yLine = [smoothy1(index1), smoothY2(index2)];
hold on
numLines = 1;
lineColors = jet(numLines);
x = randi(columns, numLines, 2);
y = randi(rows, numLines, 2);
% Now extend these lines in the overlay until the image edge.
for k = 1 : numLines
coefficients = polyfit( xLine (k, :), yLine(k, :), 1);
% Define x values to be the whole width of the image.
xFit = 1 : columns;
% Get y values. Note: some may be less than 1 or more than rows but we will adjust.
yFit = polyval(coefficients, xFit);
goodIndexes = yFit >= 1 & yFit <= rows;
xFit = xFit(goodIndexes);
yFit = yFit(goodIndexes);
% Display in overlay above the image.
line([xFit(1), xFit(end)], [yFit(1), yFit(end)], 'Color', lineColors(k, :), 'LineWidth', 3);
end
  2 Comments
Rik
Rik on 1 Dec 2022
If you have the coordinates of the red line, you should be able to find the intersection. Once you have those, finding the length is trivial, as is plotting a new line with a different color.
You can even use my point_to_line_distance function to find the boundary elements closest to the line.

Sign in to comment.

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!