Clear Filters
Clear Filters

Segmenting Colors in an RBG image

1 view (last 30 days)
Kate Heinzman
Kate Heinzman on 12 Feb 2020
Edited: KSSV on 13 Feb 2020
I originally used color segmentation using kmeans clustering to try to isolate the specific cell colors I'm trying to get out of the code.
My code looks like this:
i
mage = imread('cells.jpg');
image = image(:,:,1:3);
% Convert image from rbg to L*a*b* color space
lab_image = rgb2lab(image);
%% K-Means Clustering
% Since the color information exists in the 'a*b*' color space,
% your objects are pixels with 'a*' and 'b*' values.
ab = lab_image(:,:,2:3);
% Convert the data to data type single for use with imsegkmeans.
ab = im2single(ab);
pixel_labels = imsegkmeans(ab,2);
% For every object in your input, imsegkmeans returns an index, or a label,
% corresponding to a cluster.
% Using pixel_labels, you can separate objects in image by color
mask1 = pixel_labels == 1;
cluster1 = Ki67 .* uint8(mask1);
imshow(cluster1,[]);
cluster_mask = bwareaopen(cluster1,300); %removing noise pixels
noise_cluster = Ki67 .* uint8(cluster_mask);
imshow(noise_cluster);
imshowpair(cluster1,noise_cluster,'montage');
The image above is the original image. The image below is what I get after using the code. I only want the dark brown cells, so how do I isolate the dark brown cells? Also if you know how to be able to count the dark brown cells once they're isolated that would be great.

Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!