Calculate minimum distance in image

1 次查看(过去 30 天)
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