Image Processing (cell counting and property analysis) using MATLAB with a bright 'grid' overlay

Viewed 282

I am in the early stages of a project that is trying to analyse cell images in terms of the cell size (nice and easy) and morphology (potentially less easy, trying to find 'non-circular' cells which I suspect imfindcircles might struggle with). As part of this I need to batch process images, since there are far too many to count manually, and this is where MATLAB has come into play. testimage.bmp is an example of the image I'm looking at: Cell image

As a disclaimer, I am relatively new to image processing, until now MATLAB for me has been solely used to process signals and do large matrix computation. I've so far written some very crude code below that finds the bright and dark cells within the image, stores the centres and radii as well as counting the number of each that it finds.

clearvars; close all;
im = imread('testimage.bmp');
imshow(im);
rmin = 6;
rmax = 11;
sensitivity = 0.95;
[brightcenter,brightradii] = imfindcircles(im, [rmin rmax], 'ObjectPolarity', 'bright', 'Sensitivity',sensitivity,'Method','TwoStage');
[darkcenter,darkradii] = imfindcircles(im, [rmin rmax], 'ObjectPolarity', 'dark', 'Sensitivity',sensitivity,'Method','TwoStage');
figure(2)
imshow(im)
viscircles(brightcenter, brightradii, 'Color', 'b');
viscircles(darkcenter,darkradii);
nbright = length(brightcenter);
ndark = length(darkcenter);

The biggest problem I have hit is the grid that is in the image - I think it was placed there in the days when they used to count the images manually: Code Output

As you can see, it detects a lot of circles on the grid. Turning the sensitivity down unfortunately results in the cells not being found before the false positives are removed. I tried messing around with thresholding and turning it into a b&w image first, however, because some of the cells are light and some dark, that again seems to mean the threshold levels are sufficiently wide that the grid is still there and I end up in the same situation as before. Intuitively, the image looks very clear, so I imagine I'm missing a very obvious function, and it may well not be imfindcircles() that I've been using to date to find the cells in the image and store their properties.

If anyone has any input on how to accurately count the cells that would be appreciated! The next bit once they've been found (looking at radii and morphology) I assume shall be reasonably straightforward as my understanding is that MATLAB has analysis tools that let me pull the radii, circularity etc.

Thanks as always :)

1 Answers

You need to eliminate the lines before using imfindcircles.

Use the Sobel filter for that. You need to use a long filter to catch the long lines and not edges of circles that are similiar to short lines.

After some guess and tuning, I have that code, but you can play around to fit it to your needs:

im = double(imread('wbyai.png'));
a = kron(1:15, [1 1]);
sob_filter = [a fliplr(a); zeros(1,60); -a fliplr(-a)];
im_hor = imfilter(im, sob_filter );
im_ver = imfilter(im, sob_filter');

im2 = im;
im2(find(abs(im_hor) > 4000)) = round(mean(im(:)));   % give a value that similar to background
im2(find(abs(im_ver) > 4000)) = round(mean(im(:)));
figure; subplot(121); imshow(im, []); subplot(122); imshow(im2, []);

enter image description here

Related