Incorrect centers with bwconncomp and regionprops
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have a matrix like the one linked.
You can see it with figure,imagesc(Matrix(:,:));
I am using this programme to find the centers of the circles of the matrix:
CC = bwconncomp(Matrix);
n=26;
m=n*n;
S = regionprops(CC,'Centroid');
and it worked. But now it finds the centers at coordinates 1000,1020 and so on... I don't know why
0 comentarios
Respuestas (2)
Walter Roberson
el 21 de Mzo. de 2021
fig = openfig('Matrix.fig');
h = findobj(fig,'type','image');
Matrix = h.CData;
CC = bwconncomp(Matrix);
n=26;
m=n*n;
S = regionprops(CC,'Centroid');
cents = sortrows(vertcat(S.Centroid));
max(cents)
ans =
490.682464454976 491.909090909091
So I am not observing what you are indicating.
0 comentarios
Image Analyst
el 21 de Mzo. de 2021
I didn't run the program, but a common cause of this is people getting (x,y) confused with matrix indexes (row, column). Note that regionprops() returns Centroid as (x,y), and plot() also uses x,y. Matrices however use (row, column), which is (y, x). Make sure you know what each argument or index really represents.
By the way, this code might be useful
xy = vertcat(S.Centroid);
xCentroids = xy(:, 1);
yCentroids = xy(:, 2);
hold on;
plot(xCentroids, yCentroids, 'r+', 'LineWidth', 2, 'MarkerSize', 30);
hold off;
and next time, don't post .fig files. Post the actual text data file or a mat file - it's so much more convenient.
0 comentarios
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!