Segmenting Colors in an RBG image
1 次查看(过去 30 天)
显示 更早的评论
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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/271273/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/271274/image.jpeg)
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!