Why is it detecting 2 centroids in 1 object?

For the single object (shown on right), it is currently detecting two centroids (shown on left).
How do I correct this, such that it only detects 1 centroid per object?

댓글 수: 2

Please share your code.
labelstemp=imclose(labelstemp,se);
se=strel('disk',1);
labelstemp=imdilate(labelstemp,se);
.
.
.
s = regionprops(L, 'Orientation', 'MajorAxisLength', ...
'MinorAxisLength', 'Eccentricity', 'Centroid','solidity');

댓글을 달려면 로그인하십시오.

답변 (2개)

Torsten
Torsten 2023년 7월 31일
편집: Torsten 2023년 7월 31일
Are you sure you included the correct image file ?
I = load("labelstemp.mat");
I = I.labelstemp;
size(I,1)*size(I,2)
ans = 1690000
nnz(I(:))
ans = 388
imshow(I);hold on;
Ibw = imfill(I,'holes');
Ilabel = bwlabel(Ibw);
stat = regionprops(Ilabel,'centroid');
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro');
end
Image Analyst
Image Analyst 2023년 7월 31일

0 개 추천

I think you're mistaken, or that you attached the wrong data. Your attached data has only one blob in it. See this well commented demo. The demo should also work to mark each blob with a crosshairs in the event you change your binary image to one that has multiple blobs in it. Be aware that centroids don't always lie inside a blob, particularly if they have holes (like a donut which has the centroid in the hole), or if they are non-convex (like a C shape).
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% Load user's binary image.
StoredStucture = load("labelstemp.mat");
% Extract binary image from the structure and display it.
binaryImage = StoredStucture.labelstemp;
imshow(binaryImage, []);
impixelinfo; % Allow user to mouse around and inspect gray levels.
axis('on', 'image'); % Put up axis tick marks and labels.
% Maximize window
g = gcf;
g.WindowState = 'maximized';
% Measure the centroid of all the blobs.
props = regionprops(binaryImage, 'Centroid');
numBlobs = numel(props);
caption = sprintf('Found %d blobs.', numBlobs);
fprintf('%s\n', caption);
% Loop over all found blobs putting a red crosshairs at the centroid.
hold on;
for k = 1 : numBlobs
x = props(k).Centroid(1);
y = props(k).Centroid(2);
fprintf('Marking blob #%d. Centroid at x (column) %.1f and y (row) %.1f.\n', k, x, y);
plot(x, y, 'r+', 'MarkerSize', 60, 'LineWidth', 2);
end
% Put title atop the image.
title(caption, 'FontSize', fontSize)

카테고리

태그

질문:

2023년 7월 31일

답변:

2023년 7월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by