# count blood cells

How to count blood cells in opencv? The problem is that they stick together.

The example picture :

Maybe pairwise geometric histogram (Geometric Histograms) suitable for matching partial circle shape?

• I suggest you the reading "Microscope Image Processing", from Academic Press. I've heard there is an ebook "circulating" online. – heltonbiker Aug 9 '12 at 1:55
• @heltonbiker I didn't find there algorithm for my task just standard watershed algorithm. – mrgloom Aug 9 '12 at 6:50
• very similar: dsp.stackexchange.com/q/2516/29 – endolith Aug 27 '12 at 21:52
• @endolith but I have not separable blobs. – mrgloom Aug 28 '12 at 7:15
• @mrgloom: What? You want to count the individual circles, right? Not the blobs? – endolith Aug 28 '12 at 14:28

Just an idea with no guarantee of success:

1. isolate the red blobs (e.g. mark them as white, the rest of the image as black)
2. perform a distance transform for the white blobs (every pixel indicates the distance to the nearest black pixel)
3. perform a non-maxima-suppression (ideally only the centers of the circles remain)
4. deal with non ideal conditions (filter out small peaks from artifacts)
• looks like watershed algorithm works imagejdocu.tudor.lu/… the problem is that distance map can't handle with objects that are overlap a lot.I think I need to use circle shape somehow. dl.dropbox.com/u/8841028/blood%20cells/watershed.png dl.dropbox.com/u/8841028/blood%20cells/distance_map.png – mrgloom Aug 8 '12 at 10:53
• @mrgloom: The "circle" geometry aspect is between steps 2 and 3. For a circle, the point of maximum distance to the edges is the centre. This property holds very well even if circles overlap. You get two maxima for the combined blob. The value of each maximum corresponds to the corresponding radius, so that's one easy check in step 4: draw the circles that you expect, and measure the overlap between the circle and the blood cell. – MSalters Aug 13 '12 at 13:41

Similarly to @SalemMansour's suggestion it is also an area based approach.

A really rough estimation can be calculated if we can assume

• that the cell sizes (in pixels) are not differ very much in all the images,
• that the cell colors are not differ very much in all the images.

Then you can premeasure the average size of a cell and calculate a cheap mask for the cells like this:

from SimpleCV import *
im = Image("s58Hl.jpg")
r,g,b = im.splitChannels()
cellsize = 27*27 # premeasured cell size
print(cellnum)


It gives me ~211 for the cell count.

The mask image is like this:

For this smaller image I would manually count 9 cells:

The solution gives the result of 9.46502057613.

Of course, if any of the assumptions are invalid then this approach is useless. It is also sensitive to the hard color threshold and the cell size constant. Because of the color equalization, it can totally fail if no cell is present in the image.

But it is really simple and cheap :)

First you have to change the image to binary image by using threshold, otsu method. You can seperate the cells( overlapped cells) by using mathematical morphology such as erosion, opening. Estimate the area.

• I quite like this answer and it is pretty much what I would recommend, but it is a bit unclear. If you could edit it a bit to improve clarity I would definitely up-vote it. – nivag Apr 28 '14 at 10:42