필터 지우기
필터 지우기

Calculate minimum distance in image

조회 수: 4 (최근 30일)
Nhat Nguyen
Nhat Nguyen 2022년 12월 12일
댓글: Nhat Nguyen 2022년 12월 12일
Hi,
I have multiple sequence images like below. I want to calculate the minimum distance of 2 boundaries of black object along x axis (like the red line) and distance at a given Y-axis data.
Can you suggest me some methods?
Thank you!

채택된 답변

DGM
DGM 2022년 12월 12일
편집: DGM 2022년 12월 12일
Here's one way. You can also use pdist2() if you have it.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1227937/image.png');
% binarize it somehow
mask = rgb2gray(inpict)>200;
% get only the interior boundary curves
mask = padarray(mask,[1 1],1,'both'); % pad
mask = bwperim(mask); % get perimeter
mask = mask(2:end-1,2:end-1); % crop
% get x,y coordinates of all pixels in the curves
CC = bwconncomp(mask);
[y1 x1] = ind2sub(size(mask),CC.PixelIdxList{1});
[y2 x2] = ind2sub(size(mask),CC.PixelIdxList{2});
% find distance between all points
D = sqrt((x1-x2.').^2 +(y1-y2.').^2);
[minD idx] = min(D,[],'all','linear')
minD = 61.0328
idx = 202
% find corresponding points on each curve
[r c] = ind2sub(size(D),idx);
pointlist = [x1(r) y1(r); x2(c) y2(c)];
% show the shortest distance
imshow(mask); hold on
plot(pointlist(:,1),pointlist(:,2))
Note that this finds the minimum euclidean distance rather than simply finding the minimum horizontal width of the dark region. The latter would be simpler, but I'm assuming that's not what you want.
  댓글 수: 1
Nhat Nguyen
Nhat Nguyen 2022년 12월 12일
Thanks you, I have found answer for my question, and your answer also very helpful as my image is asymmetric.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by