How to find the arc length of a trajectory?

조회 수: 3 (최근 30일)
Julián Mauricio Ruiz Echeverri
Julián Mauricio Ruiz Echeverri 2019년 10월 14일
편집: Stephan 2019년 10월 16일
Hello , Regards!
I want to find the arc length of every length . I am trying to find the position of every point with bwmorph(img,'endpoints') but Matlab doesn't give me in order the position of every point how I need it. I tried to find the Euclidean distance between points and then the angle between them (to find the arc length L = angle * radius) but the problem is that I can't accommodate the coordinates in the correct order of each start and end of each length stretch of Arc
I have this:
img = imread('img.bmp');
img = rgb2gray(I);
g=bwmorph(img,'thin','inf');%thining
figure,imshow(g)
B1 = bwmorph(g,'endpoints');%endpoints
figure,imshow(B1);
[ye xe] = find(B1);%Position end points
  댓글 수: 1
darova
darova 2019년 10월 15일
Can't you measure the diameter? Looks like circle

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephan
Stephan 2019년 10월 15일
편집: Stephan 2019년 10월 16일
Maybe it helps if you know the center coordinates and the radius of your circle -after that you can calculate the angles and use them to calculate the arc-lengths:
% your original code
img = imread('image.bmp');
img = rgb2gray(img);
g=bwmorph(img,'thin','inf');%thining
% Find the center and radius of the circle
g1=imdilate(g,strel('square',20));
g1=bwmorph(g1,'thin','inf');
g1=imfill(g1,round((size(g1)./2)),4);
[center, radius] = imfindcircles(g1,[180 220],'ObjectPolarity','bright','Method','TwoStage','Sensitivity',0.95);
% Proceeding with your code
B1 = bwmorph(g,'endpoints');%endpoints
[ye, xe] = find(B1);%Position end points
% Sort the values to plot the lines later in the right order
Pe = [];
Pe_temp = [xe, ye, xe-center(1), center(2)-ye];
Pe = [Pe; sortrows(Pe_temp(Pe_temp(:,3)>0 & Pe_temp(:,4)>0,:),[4 -3])];
Pe = [Pe; sortrows(Pe_temp(Pe_temp(:,3)<0 & Pe_temp(:,4)>0,:),[-3 -4])];
Pe = [Pe; sortrows(Pe_temp(Pe_temp(:,3)<0 & Pe_temp(:,4)<0,:),[-4 3])];
Pe = [Pe; sortrows(Pe_temp(Pe_temp(:,3)>0 & Pe_temp(:,4)<0,:),[3 -4])];
Pe(2:numel(xe)+1,:) = Pe;
Pe(1,:) = Pe(end,:);
% Calculate Arc-Lengths
vec = [Pe(:,3), Pe(:,4)];
angles = zeros(1,numel(xe)/2);
n = 1;
for k = 1:2:numel(xe)-1
angles(n) = acosd(dot(vec(k,:)./norm(vec(k,:)),vec(k+1,:)./norm(vec(k+1,:))));
n = n + 1;
end
% Tada: The result
arc_lengths = radius*pi*angles./180;
% Plot results
figure
Lines = gobjects(1,numel(xe));
imshow(g)
hold on
for k = 1:size(Pe,1)-1
Lines(k) = drawline('Position', [Pe(k,1), Pe(k,2); center],'label',string(k));
end
scatter(xe,ye,'or')
scatter(center(1),center(2),'xg')
hold off
% Clean up
clearvars -except arc_lengths angles
The results appear to be correct to me - but you should check them by yourself. Dont miss to accept useful answers ;-)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by