How to detect Black object centers in binary image without inverse it using connected component label

3 次查看(过去 30 天)
Hi Folks,
I am trying to detect the black object centers (circles centers) from binary image (background is white and the foreground is black) .But connected component works for black background and white foreground .one condition is ,i dont want to take inverse of binary image and then apply connected comp label .. Is any way to find centers of black circles ?
i have attached my binarized image please have alook
Please help me out.....
Thank u

回答(1 个)

Gautam
Gautam 2024-9-18,8:08
Hello Bharat,
You can use connected components without inverting the image by just inverting the logic of the image while passing it to the bwconncomp” function
cc = bwconncomp(binaryImage == 0);
The code below uses this approach to find the centers of the circles in the binary image that you have attached
binaryImage = imread("Capture.png");
% Invert the image logic (without actually inverting the image data)
% Treat 0 (black) as the object
cc = bwconncomp(binaryImage == 0);
% Calculate the centroids of the connected components
stats = regionprops(cc, 'Centroid');
% Extract centroids
centroids = cat(1, stats.Centroid);
% Display the results
imshow(binaryImage);
hold on;
plot(centroids(2:end,1), centroids(2:end,2), 'r*', 'MarkerSize', 10);
title('Detected Centers of Black Circles');
hold off;
This gives the output

Community Treasure Hunt

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

Start Hunting!

Translated by