How to counting RBC size and number

조회 수: 1 (최근 30일)
Nora Hamad
Nora Hamad 2021년 8월 27일
답변: Vinay 2025년 1월 27일
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,[])

답변 (1개)

Vinay
Vinay 2025년 1월 27일
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!

Translated by