Counting large cells in an image

9 views (last 30 days)
Wael
Wael on 28 Apr 2015
Commented: Sid on 26 Jun 2015
Hi,
I am trying to use Matlab to count the large cells in the attached picture. Below is the code I used but my brain is shot after that. can you help me complete this code?
I=imread('Cells.png') figure, imshow (I); title ('Original'); BW= im2bw(I,graythresh(I)); figure; imshow (BW); title('BW'); BW1 = bwareaopen(BW,1000); figure; imshow (BW1); title('BW'); BW2=bwmorph(BW1,'dilate',5); figure; imshow (BW2); title('Dilate');
How can I get rid of the small cells so it doesn't show up in my count? Also, How can I separate the 2 attached cells to avoid counting both as one when using [labeled,numObjects]=bwlabel(BW,8);
Your help is much appreciated!
  1 Comment
Sid
Sid on 26 Jun 2015
What can you tell me about the stains on these blobs you're interested in? Is it fair to assume that they will be strong in the images? If so, check out the script below.
I = imread('cells.png');
% Looks like there is some strong presence of the stain compared to the other blobs that are in
% focus? Let's try and use that information to our advantage.
hsv_image = rgb2hsv(I);
subplot(121), imshow(I), title('original');
subplot(122), imshow(hsv_image(:,:,2)); title('strongest stains?');
% Threshold the image.
I_thresh = hsv_image(:,:,2);
I_thresh = im2bw(I_thresh,0.5);
figure, imshow(I_thresh), title('thresholded image');
% Do some cleanup.
se = strel('disk',1);
I_thresh = imclose(I_thresh,se);
I_thresh = imfill(I_thresh,'holes');
% Get rid of any other pesky blobs.
I_thresh = bwareaopen(I_thresh,200);
figure, imshow(I_thresh), title('cleaned up image')
To split the big blob, you can use a watershed transform.
% Let's concentrate on the blob at hand. Grab the biggest blob. You can of course set up a different
% filter using regionprops, and some blob selection criteria. Going to need more information on the
% blobs themselves to do that.
investigationBlob = bwareafilt(I_thresh,1);
figure, imshow(investigationBlob),title('blob to be segmented');
se2 = strel('disk',3);
% Do some cleanup on it before trying to segment.
investigationBlob = imerode(investigationBlob,se2);
% Do a bwdist transform, to be later used for a watershed transform. You can read more about it
% here: http://www.mathworks.com/help/images/ref/watershed.html.
D = bwdist(imcomplement(investigationBlob));
figure, imshow(mat2gray(D)), title('visualize the distance transform');
D = -D;
D(~investigationBlob) = -Inf;
L = watershed(D);
rgb = label2rgb(L,'jet',[.5 .5 .5]);
figure, imshow(rgb,'InitialMagnification','fit')
title('Watershed transform of D')
Of course further refinement can be introduced depending on what the unique identifiers of the blobs are.
HTH.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!