MATLAB image processing segmentation processing two

he = imread('hestain.png');% read image
figure; imshow(he), %display
title('H&E image');
text(size(he,2),size(he,1)+15, …
'Image courtesy of Alan Partin, Johns Hopkins University',…
'FontSize',7,'HorizontalAlignment','right');
cform = makecform('srgb2lab'); The structure of converting %rgb space into L a b space
lab_he = applycform(he,cform); %rgb space is converted to L
a b space
ab = double(lab_he(:,:,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);% perform K-means aggregation Class
pixel_labels = reshape(cluster_idx,nrows,ncols);
figure; imshow(pixel_labels,[]),% shows the three parts of the cluster divided into
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; %The area marked as k is set to 0
segmented_images{k} = color;
end
figure; subplot(131)
imshow(segmented_images{ 1)), %Display the first clustering area
title('objects in cluster 1'); subplot(132),
imshow(segmented_images{2}), %Display the second clustering area
title('objects in cluster 2 '); subplot(133),
imshow(segmented_images{3}),% show the third clustering area
title('objects in cluster 3');
mean_cluster_value = mean(cluster_center,2);% calculate the mean value
[tmp, idx ] = sort(mean_cluster_value);%sort
blue_cluster_num = idx(1);% minimum
L = lab_he(:,:,1);% brightness component
blue_idx = find(pixel_labels == blue_cluster_num);% blue area label
L_blue = L(blue_idx);
is_light_blue = im2bw( L_blue,graythresh(L_blue));% converted to binary image
nuclei_labels = repmat(uint8(0),[nrows ncols]);
nuclei_labels(blue_idx(is_light_blue==false)) = 1;% dark blue area label
nuclei_labels = repmat( nuclei_labels,[1 1 3]);
blue_nuclei = he;
blue_nuclei(nuclei_labels ~= 1) = 0;% other areas outside the dark blue area are set to 0
figure, imshow(blue_nuclei),% displays the dark blue area
title('blue nuclei');
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/115259638