Cluster Image Intensity using K-Means Clustering

Clustering is the most common unsupervised learning technique. It is used for exploratory data analysis to find hidden patterns or groupings in data. Applications for cluster analysis include e-commerce pattern, market research, and clustering of images etc.

k-means clustering is a partitioning method. The function kmeans partitions data into k mutually exclusive clusters and returns the index of the clustered data.

Each cluster in a k-means partition consists of data index and a centroid . In each cluster, kmeans minimizes the sum of the distances between the centroid and all member objects of the cluster.

The image which is used below, it is captured during nuclear fusion in a controlled lab.

Intensity Based Clustering of an Image Using Statistics and Machine Learning and Image Processing Toolbox for K (No of Clusters)= 1 to 4

Read and Visualize Image

im=imread('image1.tif'); % YOu can download this image and rename it as image1.tif in MATLAB.
figure
imshow(im)
Nuclear Fusion Image

Cluster Image using Statistics and Machine Learning Toolbox

im=imread('image1.tif');
figure
imshow(im)
x=reshape(im,size(im,1)*size(im,2),1);
k=[ 1 2 3 4];
figure
for i=1:4
    [ L ,Centers]=kmeans(double(x),k(i));
    y=reshape(L,size(im,1),size(im,2));
    B=labeloverlay(im,y);
    subplot(2,2,i);
    imshow(B)
    kk=k(i);
    pp=[ 'For Cluster k','=',num2str(kk)];
    
       title(pp)

end
Clustered Images for K= 1,2,3,4

Intensity Based Clustering of an Image Using Image Processing Toolbox for K (No of Clusters)= 1 to 4

figure

k=[ 1 2 3 4];
for i=1:4
    [ L ,Centers]=imsegkmeans(im,k(i));
    B=labeloverlay(im,L);
    subplot(2,2,i);
    imshow(B)
    kk=k(i);
    pp=[ 'For Cluster k','=',num2str(kk)];
    
       title(pp)
end

Watch YouTube video for explanation in details

3 thoughts on “Cluster Image Intensity using K-Means Clustering”

  1. I’m still learning from you, while I’m trying to achieve my goals. I definitely liked reading everything that is posted on your site.Keep the information coming. I enjoyed it!

  2. Someone essentially help to make seriously posts I would state. This is the very first time I frequented your website page and thus far? I amazed with the research you made to make this particular publish incredible. Excellent job!

Leave a Reply

Your email address will not be published.