I am trying to find the exact distance of a curvy line.

6 ビュー (過去 30 日間)
Sidney Todd
Sidney Todd 2021 年 7 月 21 日
コメント済み: Walter Roberson 2021 年 7 月 22 日
I am needing to find the distance of the line outlined in red. I was thinking i could filter the photo and find the line distance by pixel count but havent been able to succeed this way. Anything advice is much appreciated.
The original photo and the edited version are both attached.
The blue line drawn on the original photo is the same as the red boundary on the edited version. It is just for reference.
my code is below-
clear
clc
close all
I = imread('ss3.png');
% imshow(I)
hold on
% J=imcrop(I)
J=rgb2gray(I);
BW1=edge(J,'sobel',.009,'horizontal');
mask = imclose(BW1, true(7));
mask = conv2(double(mask), ones(3), 'same') > 3; % Adjust number to control the size of the new mask.
mask = imfill(mask, 'holes'); % Remove any interior holes
%imshow(mask)
%Auto crop image using set points----------------------------------------
I2 = imcrop(mask,[407.51 0.51 83.98 1037.98]);
imshow(I2,'InitialMagnification', 'fit')
%boundary outline and trace -----------------------------------------
[B,L] = bwboundaries(I2,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 0.5)
end
  4 件のコメント
Image Analyst
Image Analyst 2021 年 7 月 22 日
All we can see are the version with the red or blue annotation lines or regions already drawn into the image. We don't see either image with no red or blue lines draw in/over it.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2021 年 7 月 21 日
編集済み: Matt J 2021 年 7 月 21 日
Why not as follows?
I2 = imread('image.jpeg');
blue=bwareafilt( I2(:,:,1)<=50 & I2(:,:,2)<=50 & I2(:,:,3)>=200, 1);
Length=getfield( regionprops(blue,'Perimeter') ,'Perimeter')
Length = 1.6471e+03
  1 件のコメント
Sidney Todd
Sidney Todd 2021 年 7 月 22 日
what units would this by default be in?

サインインしてコメントする。

その他の回答 (2 件)

J. Alex Lee
J. Alex Lee 2021 年 7 月 21 日
Assuming that the boundary points are ordered well (adjacently), then you can calculate the cummulative square distance between adjacent points to get the approximate arclength along the curve
x = boundary(:,1);
y = boundary(:,2);
dx = diff(x);
dy = diff(y);
d = sqrt(dx.^2+dy.^2);
L = sum(d)

Walter Roberson
Walter Roberson 2021 年 7 月 21 日
The exact distance along a curved line is very likely to be an irrational number.
You have approximations of curves. What distance you measure depends upon the approximation model you use. The more accurately you approximate, the more the answer can change.
  2 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by