Incorrect centers with bwconncomp and regionprops

1 回表示 (過去 30 日間)
Alberto Paniate
Alberto Paniate 2021 年 3 月 21 日
回答済み: Image Analyst 2021 年 3 月 21 日
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

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 3 月 21 日
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.

Image Analyst
Image Analyst 2021 年 3 月 21 日
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.

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by