0% found this document useful (0 votes)
12 views5 pages

Exp No.5

The document describes steps to segment an image of tissue stained with hematoxylin and eosin using k-means clustering. It involves converting the image to L*a*b color space, clustering the a* and b* color channels into 3 groups, and segmenting the dark blue cluster containing cell nuclei.

Uploaded by

Taha GH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Exp No.5

The document describes steps to segment an image of tissue stained with hematoxylin and eosin using k-means clustering. It involves converting the image to L*a*b color space, clustering the a* and b* color channels into 3 groups, and segmenting the dark blue cluster containing cell nuclei.

Uploaded by

Taha GH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Medical Instrumentation Technology Engineering

Experiment No.5

Prepared BY:
Taha Ghassan Adnan

Supervised BY: Mrs. Marwa Mofak


Experiment No.5
Edge detection

Color-Based Segmentation Using K-Means Clustering


Step 1: Read Image
Read in hestain.png, which is an image of tissue stained with hematoxylin and eosin (H&E). This
staining method helps pathologists distinguish different tissue types.

The Code
he = imread('E:\Image Process\image(2).jpg');
imshow(he), title('H&E image');
text(size(he,5),size(he,1)+15,...
'NTU University');

Step 2: Convert Image from RGB Color Space to L*a*b* Color Space
The L*a*b* space consists of a luminosity layer 'L*', chromaticity-layer 'a*' indicating where color falls
along the red-green axis, and chromaticity-layer 'b*' indicating where the color falls along the blue
yellow axis. All of the color information is in the 'a*' and 'b*' layers. You can measure the difference
between two colors using the Euclidean distance metric. Convert the image to L*a*b* color space
using rgb2lab
The Code
he = imread('E:\Image Process\image(1).jpg');
imshow(he), title('H&E image');
text(size(he,5),size(he,1)+15,...
'NTU University');
lab_he = rgb2lab(he);
imshow(lab_he)

1|Page
Step 3: Classify the Colors in 'a*b*' Space Using K-Means Clustering
Clustering is a way to separate groups of objects. K-means clustering treats each object as having a
location in space. It finds partitions such that objects within each cluster are as close to each other as
possible, and as far from objects in other clusters as possible. K-means clustering requires that you
specify the number of clusters to be partitioned and a distance metric to quantify how close two objects
are to each other. Since the color information exists in the 'a*b*' color space, your objects are pixels
with 'a*' and 'b*' values. Convert the data-to-data type single for use with imsegkmeans. Use
imsegkmeans to cluster the objects into three clusters.

The Code
%% function is used to Convert image to single precision
nColors = 3;
pixel_labels = imsegkmeans(ab,nColors,'NumAttempts',3);
imshow(pixel_labels,[])
title('Image Labeled by Cluster Index');

2|Page
Step 4: Create Images that Segment the H&E Image by Color
Using pixel labels, you can separate objects in hestain.png by color, which will result in three images.

The Code
%%
mask1 = pixel_labels==1;
cluster1 = he .* uint8(mask1);
imshow(cluster1)
title('Objects in Cluster 1');
mask2 = pixel_labels==2;
cluster2 = he .* uint8(mask2);
imshow(cluster2)
figure
title('Objects in Cluster 2');
mask3 = pixel_labels==3;
cluster3 = he .* uint8(mask3);
imshow(cluster3)
figure
title('Objects in Cluster 3');

3|Page
Step 5: Segment the Nuclei
Cluster 3 contains the blue objects. Notice that there are dark and light blue objects. You can separate
dark blue from light blue using the 'L*' layer in the L*a*b* color space. The cell nuclei are dark blue.
Recall that the 'L*' layer contains the brightness values of each color. Extract the brightness values of
the pixels in this cluster and threshold them with a global threshold using imbinarize. The mask
is_light_blue gives the indices of light blue pixels.

The Code
%%
L = lab_he(:,:,1);
L_blue = L .* double(mask3);
L_blue = rescale(L_blue);
idx_light_blue = imbinarize(nonzeros(L_blue));
imshow(L)
%%
blue_idx = find(mask3);
mask_dark_blue = mask3;
mask_dark_blue(blue_idx(idx_light_blue)) = 0;
blue_nuclei = he .* uint8(mask_dark_blue);
imshow(blue_nuclei)
title('Blue Nuclei');

4|Page

You might also like