How to distinguish different color cells in the image?
1 view (last 30 days)
Show older comments
larry liu
on 23 Jun 2021
Commented: Image Analyst
on 23 Jun 2021
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.
0 Comments
Accepted Answer
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
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);
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!