8

I'm relatively new to OpenCV and I do not have a strong image processing background. Currently I am working on a project to write a program to count all the biological cells from microscope in an image. I have tried various method from Internet sources to apply counting on the image, but none of them work well as expected.

Some of the methods I have used are:

  1. Finding contours of the filtered image. (does not work well with cells that are close together)
  2. Gaussian blur and find local maxima on the image. (same problem as 1)
  3. Canny Edge detection (output result detect non cells segment)

This is an example of the image I need to count the total number of cells.

enter image description here

My current counting algorithm works better if the cells are not close together. For example like this:

enter image description here

However, the algorithm still fail to split apart the 3 cells that are sticked together in the center of the image.

So what could I do to detect total number of cells in an image with least false negative/positive?

Woody
  • 612
  • 9
  • 21
  • 3
    Have a look at this page: http://stackoverflow.com/questions/5298884/finding-number-of-colored-shapes-from-picture-using-python and http://codegolf.stackexchange.com/questions/40831/counting-grains-of-rice May be similar to what you are looking for! – Patrick Yu Nov 16 '15 at 07:16
  • is the size of each cell similar? – Micka Nov 16 '15 at 08:52
  • @Micka the cell size in each image is similar, but there are different image for different zoom level, so cell size from one image cannot be applied to another image – Woody Nov 17 '15 at 06:26
  • @Woody: I meant whether in ONE image all cells have a similar size. You could use that information to decide whether it is likely that one of your detected cells might be two touching cells. – Micka Nov 17 '15 at 07:10
  • @Micka sorry for late response. All the cells in one image should have similar size, do you mean I can use the cell size area to determine number of cells in large contours?? – Woody Nov 25 '15 at 05:08

1 Answers1

2

Your approach is almost fine. However, it needs some additional steps. You need something called Morphological Operations.

  1. Filter your image in the way you thing is good.
  2. Apply a threshold depending on color or convert it to gray then threshold it. P.S. from the examples you provided, it seems that your cell color is too saturated. So, you may convert it to HSV Space and then threshold it using the S channel (tell me if you need help here).
  3. Apply the Opening Morphological Operators on the thresholded image. P.S. you may to try few kernal size and choose the best.
  4. Take contours and do what you were doing.

Opening:

cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5, 5), cv::Point(1, 1));
cv::morphologyEx(img, img, cv::MORPH_OPEN, element, cv::Point(-1, -1), 1);
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • how do I perform opening operators on the image?? – Woody Nov 17 '15 at 06:24
  • I tried your Opening operator, and I change the MORPH_RECT to MORPH_ELLIPSE, the detection is better than before! But there are still false negative where the cell is not detected. – Woody Nov 23 '15 at 07:55
  • in computer vision there is not 100% correct results. There will be false positive and missed real circles. However, you could post the result you are getting so I may be able to help to reduce the false positives but NOT TO CANCEL ALL of them – Humam Helfawi Nov 23 '15 at 07:57
  • please refer to the image below: 1) processed image: [link](http://i.imgur.com/1DbteMP.png) 2) labelled image: [link](http://i.imgur.com/Z5HNC9T.png) the original image is the one in labelled image without those dot label – Woody Nov 25 '15 at 05:12
  • as I have seen, the problem is in the very close to each other cells. You probably can not solve it using just the morphological operations while you trying to get 100% results. However, try to play with thresholds.. the number of iteration which was set to one and the kernel size which was set to 5. – Humam Helfawi Nov 25 '15 at 06:56
  • the current result already have kernel size=5 with iteration=1, I apply threshold and gaussian blur before opening as without the gaussian blur, the detection doesn't work properly. How do I get all the maxima point on the source image with opencv?? – Woody Nov 26 '15 at 07:25
  • try to filter it depending on the S channel it should work.. but give attention while showing the image you should convert it back to BGR – Humam Helfawi Nov 26 '15 at 07:45
  • do you know how to find all the local maxima points in image with OpenCV?? I tried to search through the internet, but I couldn't find any working example for my current case. – Woody Nov 30 '15 at 02:38