![]() |
VOOZH | about |
Segmentation By clustering
It is a method to perform Image Segmentation of pixel-wise segmentation. In this type of segmentation, we try to cluster the pixels that are together. There are two approaches for performing the Segmentation by clustering.
Clustering by merging or Agglomerative Clustering:
In this approach, we follow the bottom-up approach, which means we assign the pixel closest to the cluster. The algorithm for performing the agglomerative clustering as follows:
The agglomerative clustering is represented by Dendrogram. It can be performed in 3 methods: by selecting the closest pair for merging, by selecting the farthest pair for merging, or by selecting the pair which is at an average distance (neither closest nor farthest). The dendrogram representing these types of clustering is below:
Clustering by division or Divisive splitting
In this approach, we follow the top-down approach, which means we assign the pixel closest to the cluster. The algorithm for performing the agglomerative clustering as follows:
In this article, we will be discussing how to perform the K-Means Clustering.
K-Means Clustering
K-means clustering is a very popular clustering algorithm which applied when we have a dataset with labels unknown. The goal is to find certain groups based on some kind of similarity in the data with the number of groups represented by K. This algorithm is generally used in areas like market segmentation, customer segmentation, etc. But, it can also be used to segment different objects in the images on the basis of the pixel values.
The algorithm for image segmentation works as follows:
Following are the steps for applying the K-means clustering algorithm:
For a certain class of clustering algorithms, there is a parameter commonly referred to as K that specifies the number of clusters to detect. We may have the predefined value of K, if we have domain knowledge about data that how many categories it contains. But, before calculating the optimal value of K, we first need to define the objective function for the above algorithm. The objective function can be given by:
Where j is the number of clusters, and i will be the points belong to the jth cluster. The above objective function is called within-cluster sum of square (WCSS) distance.
A good way to find the optimal value of K is to brute force a smaller range of values (1-10) and plot the graph of WCSS distance vs K. The point where the graph is sharply bent downward can be considered the optimal value of K. This method is called Elbow method.
For image segmentation, we plot the histogram of the image and try to find peaks, valleys in it. Then, we will perform the peakiness test on that histogram.