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)
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
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