Borrar filtros
Borrar filtros

Calculate minimum distance in image

10 visualizaciones (últimos 30 días)
Nhat Nguyen
Nhat Nguyen el 12 de Dic. de 2022
Comentada: Nhat Nguyen el 12 de Dic. de 2022
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!

Respuesta aceptada

DGM
DGM el 12 de Dic. de 2022
Editada: DGM el 12 de Dic. de 2022
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 comentario
Nhat Nguyen
Nhat Nguyen el 12 de Dic. de 2022
Thanks you, I have found answer for my question, and your answer also very helpful as my image is asymmetric.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Image Processing Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by