distance between several objects in binary image

조회 수: 2 (최근 30일)
Abo
Abo 2014년 12월 1일
댓글: Faiz Yusoff 2021년 2월 20일
Does anyone know how can I find distance between these three animals from each other in a binary image (distance between each two red points)?

채택된 답변

Image Analyst
Image Analyst 2014년 12월 1일
I already gave code for something almost identical to that here.
  댓글 수: 6
Image Analyst
Image Analyst 2021년 2월 20일
@Faiz Yusoff I already answered this in another post of yours.
Faiz Yusoff
Faiz Yusoff 2021년 2월 20일
noted thank you so much!

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

추가 답변 (1개)

yanqi liu
yanqi liu 2021년 2월 20일
sir, may be use the follow code
clc; clear all; close all;
img=imread('image.jpeg');
J = rgb2lab(img);
a = mat2gray(J(:,:,2));
bw = im2bw(a, graythresh(a));
bw = imclose(bw, strel('disk', 5));
stats = regionprops(bw);
cens = cat(1, stats.Centroid);
figure;
imshow(img);
hold on;
plot(cens(:,1), cens(:,2), 'co', 'MarkerFaceColor', 'c');
dis_m = [];
for i = 1 : size(cens, 1)
pti = cens(i,:);
if i > size(cens, 1)/2+1
continue;
end
for j = 1 : size(cens, 1)
if i == j
continue;
end
ptj = cens(j,:);
dis = norm(pti-ptj);
dis_m(i,j) = dis;
plot([pti(1) ptj(1)], [pti(2) ptj(2)], 'r--', 'LineWidth', 2);
text(mean([pti(1) ptj(1)]), mean([pti(2) ptj(2)]), sprintf('%.1f', dis), 'Color', 'm', 'FontSize', 15);
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by