# How do I know the length from the center of the object to the vertical axis edge and the horizontal axis edge?

2 visualizaciones (últimos 30 días)
Kantachai Chamnarnkit el 31 de En. de 2023
Comentada: Image Analyst el 31 de En. de 2023
Here's a picture of the pill, you can see that it's not a circle. I want to know the length from the center to the vertical axis edge and the horizontal axis edge
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Bora Eryilmaz el 31 de En. de 2023
You can do something along these lines, where the location of the centroids seems like what you want:
Ibw = im2bw(I);
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
imshow(I);
hold on;
for i = 1:numel(stat)
plot(stat(i).Centroid(1), stat(i).Centroid(2), 'ro');
stat(i)
end
ans = struct with fields:
Centroid: [961.5471 479.7054]
ans = struct with fields:
Centroid: [956.8800 409.4163]
ans = struct with fields:
Centroid: [951 63]
ans = struct with fields:
Centroid: [997 448]
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Image Analyst el 31 de En. de 2023
Or
xyCentroids = vertcat(stats); % N by 2 array. x in column 1, y in column 2
% Or if you want them in separate vectors:
xCentroids = xyCentroids(:, 1);
yCentroids = xyCentroids(:, 2);

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by