number of WBC's in an image based on size.

6 views (last 30 days)
i have written a code to find the number of WBC's in an image based on size. But once the WBC's are highlighted the imfindcircles is not finding it and it is not getting counted.
sum=0;
for l= 104:104
jpgFilename = strcat('2_images_', num2str(l), '.jpg');
wbc=imread('2_images_104.jpg');
figure(1);
imshow(wbc);
title('original image');
%%converted into gray scale
wbc1=rgb2gray(wbc);
%%thresholding
T=64;
[m n]=size(wbc1)
for i=1:m
for j=1:n
if wbc1(i,j)>T
wbc1(i,j)=255;
else
wbc1(i,j)=0;
end
end
end
figure(2);
imshow(wbc1);
title('thresholded');
%%complement the image
wbc2=imcomplement(wbc1);
%%erosion of the image
A1 = strel('diamond',1);
A=imerode(wbc2,A1);
A2=imerode(A,A1);
A3=imerode(A2,A1);
figure(3);
imshow(A3);
title('eroded');
%%using edge detection
BW1 = edge(A3,'canny');
figure(4);
imshow(BW1);
title('edge detection');
A1=strel('diamond',3);
BW2=imdilate(BW1,A1);
BW3=imdilate(BW1,A1);
BW4=imdilate(BW3,A1);
figure(5);
imshow(BW4);
title('dilated');
BW5=imfill(BW4,'holes');
%%counting the number of WBC
[centers, radii, metric] = imfindcircles(BW5,[1 2],'ObjectPolarity','dark','Sensitivity',0.86,'Method','twostage');
m = viscircles(centers,radii);
[a,b]=size(centers);
fprintf('the number of WBCs in an image %d\n',a);
sum=sum+(a);
end
fprintf('the total number of WBCs in all images %d',sum);
this is the code. please help me
  7 Comments
Bhavna Rajasekaran
Bhavna Rajasekaran on 14 Jul 2019
Offcourse its unclear how the wbc image looks like or the final BW5 image that is the input to imfindcircles.. That could rather help in answwering this question better...
Have you tried regionprops for finding centroids of WBC?
Image Analyst
Image Analyst on 14 Jul 2019
Attach an original gray scale image if you still have problems.

Sign in to comment.

Answers (1)

Harshal Faldu
Harshal Faldu on 14 Nov 2019
Thank you for this ,
Please can you give something about how to count types of WBC in the blood image

Categories

Find more on Biomedical Imaging in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!