How to distinguish different color cells in the image?

2 views (last 30 days)
I have an image with two different color cells like below shows
and I need to claasify it and count how much cells like below shows red and yellow
how can I do that?
I have tried edge detection but it seems doesnt work.

Accepted Answer

Image Analyst
Image Analyst on 23 Jun 2021
They don't look very different to me. I'd try the Color Thresholder on the Apps tab of the tool ribbon. Try HSV and RGB color spaces and see if you can get differentiation.
  2 Comments
larry liu
larry liu on 23 Jun 2021
if I got the image like this, then how can I count the number of circles?
Image Analyst
Image Analyst on 23 Jun 2021
You can first get rid of the grid with imclearborder(). That might get rid of some blobs that are connected to it though. If you don't want to lose them, then don't use a grid.
Then you can find round particles by looking at their circularity.
mask = imclearborder(mask); % Get rid of grid and blobs touching it.
mask = imfill(mask, 'holes');
props = regionprops(mask, 'BoundingBox', 'Area', 'Perimeter');
bb = vertcat(props.BoundingBox);
widths = bb(:, 3);
heights = bb(:, 4);
aspectRatios = widths ./ heights;
allAreas = [props.Area];
allPerimeters = [props.Perimeter];
circularities = allPerimeters .^ 2 ./ (4 * pi * allAreas);
% Get indexes of blobs where aspect ratio is less than about 3 and
% circularities less than about 5. Adjsut as needed.
keeperIndexes = (circularities < 5) & ...
(aspectRatios < 3) & ...
(1./aspectRatios < 3)
[labeledImage, numInitialBlobs] = bwlabel(mask);
fprintf('Before shape filtering, found %d blobs.\n', numInitialBlobs);
mask = ismember(labeledImage, find(keeperIndexes));
imshow(mask);
% Remeasure with the filtered set of blobs.
props = regionprops(mask, 'BoundingBox', 'Area', 'Perimeter');
numFinalBlobs = length(props);
fprintf('After filtering, found %d blobs.\n', numFinalBlobs);

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!