![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1774695/image.png)
How to detect Black object centers in binary image without inverse it using connected component label
조회 수: 1 (최근 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
댓글 수: 0
답변 (1개)
Gautam
2024년 9월 18일
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1774695/image.png)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!