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

1 次查看(过去 30 天)
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 个评论
Rik
Rik 2022-12-1
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by