I want to find end to end distance of this skeleton image

조회 수: 3 (최근 30일)
Adarsh Tripathi
Adarsh Tripathi 2022년 6월 25일
댓글: Adarsh Tripathi 2022년 6월 26일
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1045155/insect.jpg';
k = imread(filename);
k = rgb2gray(k);
%imshow(insect);
%applyig threshold to convert the image into binary so that backgroung can
%be separated
BI = k < 160;
%imshow(BI)
BI = bwareaopen(BI,40);
%imshow(BI)
%finding the skeleton of image
k = bwskel(BI);
%imshow(k);
[a b]=size(k);
output=zeros(a,b);
for i=2:a-1
for j=2:b-1
ws=[k(i-1,j-1),k(i-1,j),k(i-1,j+1),k(i,j-1),k(i,j)...
,k(i,j+1),k(i+1,j-1),k(i+1,j),k(i+1,j+1)];
kg=sum(ws);
if(k(i,j)==1 && kg==2)
output(i,j)=1;
end
end
end
figure;
output=imdilate(output,strel('diamond',5));
imshow(output+k);
i have this code with which i highlighted the end points but dont know how to go further
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 6월 25일
It is not obvious to me which are the endpoints, unless you mean the endpoints of every one of the (sometimes very short) line segments ?
Adarsh Tripathi
Adarsh Tripathi 2022년 6월 25일
편집: Adarsh Tripathi 2022년 6월 25일
Thanks for your reply @walter Roberson Actually I attached the image before the code named insect in which end points are clearly specified i don't know how this below image is visible. And also just after sometime of posting i solved it myself but again thanks for your early reply.

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

답변 (1개)

Image Analyst
Image Analyst 2022년 6월 25일
What exactly is the end to end distance? Do you mean the Feret diameter bwferet?
Do you mean the sum of all white pixels to the neighbor pixels? Have you tried pdist2, and extract all pairs just 1 or sqrt(2) pixels apart, sum them, and divide by 2? Something like (untested):
[y, x] = find(k); % Find coordinates.
xy = [x(:), y(:)]; % Combine into matrix.
distances = pdist2(xy, xy); % Find distance of every point to every other point.
mask = distances < mean([sqrt(2), sqrt(3)]); % Find pixels that are adjacent or on nearest diagonal ONLY.
sumOfDistances = sum(distances(mask)) / 2 % Divide by 2 since we get the sum for each endpoint so it's counted twice.
  댓글 수: 9
Walter Roberson
Walter Roberson 2022년 6월 26일
I wonder if you could describe why that distance is significant? I would have expected it to be more significant to trace along the curve, to measure the length of the creature, instead of calculating something about how much it is curled up at the moment?
Adarsh Tripathi
Adarsh Tripathi 2022년 6월 26일
@walter Roberson That is significant because changing of that distance will give the activity of the worm with time.

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by