Incorrect centers with bwconncomp and regionprops
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 21 Mar 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 Comments
Image Analyst
on 21 Mar 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 Comments
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!