How to convert image from clustering to Gray image?

1 vue (au cours des 30 derniers jours)
menna gamal
menna gamal le 15 Avr 2015
Modifié(e) : Ashish Uthama le 15 Avr 2015
i work in blood cell image , i used clustering to extract red blood cell only without white blood cell i did it and its work in this code , my problem is i want to convert the final image to gray image or RGB , i don't know the type of the final image(blue_nuclei) the image i want to convert to gray named is (blue_nuclei) in code this is my code :
he = imread('CL_13-09_image2.jpg');
figure(1),imshow(he), title('H&E image');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure(2),imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
figure(3),imshow(segmented_images{1}), title('objects in cluster 1');
figure(4),imshow(segmented_images{2}), title('objects in cluster 2');
figure(5),imshow(segmented_images{3}), title('objects in cluster 3');
mean_cluster_val = zeros(3,1);
for k = 1:nColors
mean_cluster_val(k) = mean(cluster_center(k));
end
[mean_cluster_val,idx] = sort(mean_cluster_val);
blue_cluster_num = idx(2);
L = lab_he(:,:,1);
blue_idx = find(pixel_labels == blue_cluster_num);
L_blue = L(blue_idx);
is_light_blue = im2bw(L_blue,graythresh(L_blue));
nuclei_labels = repmat(uint8(0),[nrows ncols]);
nuclei_labels(blue_idx(is_light_blue==false)) = 1;
nuclei_labels = repmat(nuclei_labels,[1 1 3]);
blue_nuclei = he;
blue_nuclei(nuclei_labels ~= 1) = 0;
figure(6),imshow(blue_nuclei), title('blue nuclei');
my image i work on :

Réponses (0)

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by