Incorrect centers with bwconncomp and regionprops
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
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.
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!