Counting the individual objects in binary image without built-in functions
3 次查看(过去 30 天)
显示 更早的评论
I have preprocessed an image to obtain following binary image of overlapping stem cells. How do I count the individual cells on the image WITHOUT using built-in functions but only morphological algorithms?
I tried watershed transform but got weird outputs and still can't figure out the "counting the cells" part.
Here is what I tried:
binary = imread("1A_Binary_Image.png")
% distance transform
D = bwdist(~binary);
imshow(D,[])
title('distance transform')
% complement of distance transform
D = -D;
% watershed transform
L = watershed(D);
L(~binary) = 0;
rgb = label2rgb(L,'jet',[.5 .5 .5]);
imshow(rgb)
title('Watershed Transform')
1 个评论
采纳的回答
VINAYAK LUHA
2023-9-22
Hi Eren,
It is my understanding that you have a binary image containing several overlapping cells and wish to segregate overlapping cells into individual cells and count their numbers using only Morphological Transformations.
To prevent the over segmentation you have been facing, remove the shallow minima from the image by using the “imhmin” function before calling the watershed function.
As for the counting part, you can use Depth first search(DFS) or Breadth First Search(BFS) algorithm to count the number of connected components i.e. group of ones in the image. Refer to the solution tab on the following website for more information https://leetcode.com/problems/number-of-islands/solutions/ .
In case you wish to settle with builtin functions here’s the improved code for your reference based on the suggestions –
img = imread("Image Path");
D = bwdist(~img);
D = -D;
D = imhmin(D, 2);
L = watershed(D);
L(~img) = 0;
L = imbinarize(L);
L = bwareaopen(L, 500);
RGB = label2rgb(L, 'jet', 'k', 'shuffle');
imshow(RGB);
CC = bwconncomp(L);
S = regionprops(CC, 'Centroid');
title("Number of Cells: "+ num2str(numel(S)));
hold on;
for k = 1:numel(S)
centroid = S(k).Centroid;
plot(centroid(1), centroid(2), 'r+', 'MarkerSize', 10, 'LineWidth', 2);
end
hold off;
Result
Regards
Vinayak Luha
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Feature Detection and Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!