How to counting RBC size and number

3 views (last 30 days)
Nora Hamad
Nora Hamad on 27 Aug 2021
Answered: Vinay on 27 Jan 2025
i write this code but i cant get number of rbc and this is my input image
clear all;
close all;
clc;
count=0;
RC_Im = imread('red_cells.png');
RC_Im = rgb2gray(RC_Im);
level=graythresh(RC_Im);
RC_Im_BW = im2bw(RC_Im,level);
figure;
imshow(RC_Im_BW,[])
[x,z]=size(RC_Im_BW);
for R=0:1:60
SE = strel('disk',R);
afteropen=imopen(RC_Im_BW,SE);
if RC_Im_BW==1
count=count+1;
end
end
figure;
imshow(afteropen,[])

Answers (1)

Vinay
Vinay on 27 Jan 2025
The binary image comparison 'RC_Im_BW==1' compares the entire image rather than individual objects.The 'bwlabel' can be used to label connected components in the binary image which counts the number of distinct objects.
%morphological operations
RC_Im_BW_cleaned = imopen(RC_Im_BW,strel('disk', 5));
% Label connected components
[labeledImage, numRBCs] = bwlabel(RC_Im_BW_cleaned);
% Print the count of RBCs
fprintf('Number of RBCs: %d\n', numRBCs);
Refer to the below documentation of 'bwlabel' for more details.

Community Treasure Hunt

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

Start Hunting!