Info
This question is closed. Reopen it to edit or answer.
Is it possible to separate R portion, G portion, B portion of an RGB image?
1 view (last 30 days)
Show older comments
a = imread('eye.jpg');
imshow(a);title('H&E image');
text(size(a,2),size(a,1)+15,...
'Image Courtesy of Alen Partin,Johns Hopkins University',...
'FontSize',7,'HorizontalAlignment','right');
cform = makecform('srgb2lab');
lab_i = applycform(a,cform);
ab = double(lab_i(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx,cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean',...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]),title('image labeled by clusterindex');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = a;
color(rgb_label~=k) = 0;
segmented_images{k} = color;
end
imshow(segmented_images{1}),title('objects in cluster 1');
imshow(segmented_images{2}),title('objects in cluster 2');
If anyone knew some other program like this please post here..:)
1 Comment
jonas
on 1 Mar 2018
This is the third time I have seen you post this code in the last 24h. I suggest you read up on Imread and how images are described by pixels.
Answers (0)
This question is closed.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!