Counting the individual objects in binary image without built-in functions

3 visualizaciones (últimos 30 días)
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?
binary image of overlapping stem cells
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')

Respuesta aceptada

VINAYAK LUHA
VINAYAK LUHA el 22 de Sept. de 2023
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

Más respuestas (0)

Categorías

Más información sobre Feature Detection and Extraction en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by