-
Image segmentation is a branch of digital image processing which focuses on partitioning an image into different parts according to their features and properties. The primary goal of image segmentation is to simplify the image for easier analysis. In image segmentation, you divide an image into various parts that have similar attributes.
-
By using image segmentation techniques, you can divide and group-specific pixels from an image, assign them labels and classify further pixels according to these labels.
-
You can draw lines, specify borders, and separate particular objects (important components) in an image from the rest of the objects (unimportant components).
-
Image segmentation allows us to decompose an image into meaningful parts and understand a scene at a more granular level. In this way, it differs from other computer vision tasks you might be familiar with. While image classification is helpful for seeing what’s in an image in general, and object detection allows us to locate and tracking the contents of an image, segmentation allows us to define and understand the shapes and boundaries of objects in an image.
-
We can readily see the power of image segmentation when we consider its flexibility in photo editing software. From automatically separating backgrounds and foregrounds, to cutting out segmented people and objects, to creating responsive portrait modes, image segmentation offers a wide range of capabilities for these kinds of creativity tools.
- K-Means Clustering is an unsupervised learning algorithm that is used to solve the clustering problems in machine learning or data science. In this topic, we will learn what is K-means clustering algorithm, how the algorithm works, along with the Python implementation of k-means clustering.
- K-Means Clustering is an Unsupervised Learning algorithm, which groups the unlabeled dataset into different clusters. Here K defines the number of pre-defined clusters that need to be created in the process, as if K=2, there will be two clusters, and for K=3, there will be three clusters, and so on.
- Having clustering methods helps in restarting the local search procedure and remove the inefficiency. In addition, clustering helps to determine the internal structure of the data.
- This clustering analysis has been used for model analysis, vector region of attraction.
- Clustering helps in understanding the natural grouping in a dataset. Their purpose is to make sense to partition the data into some group of logical groupings.
- Clustering quality depends on the methods and to the identification of hidden patterns.
- They play a wide role in applications like marketing economic research and weblogs to identify similarity measures, Image processing, and spatial research.
- They are used in outlier detections to detect credit card fraudulence.
The K Means Clustering for image segmentation works in the following manner: Let’s see how does K-means clustering work –
- Choose the number of clusters you want to find which is K.
- Randomly assign the data points to any of the K clusters.
- Then calculate the center of the clusters.
- Calculate the distance of the data points from the centers of each of the clusters.
- Depending on the distance of each data point from the cluster, reassign the data points to the nearest clusters.
- Again calculate the new cluster center.
- Repeat steps 4,5 and 6 till data points don’t change the clusters, or till we reach the assigned number of iterations.
The code for image segementation works on the following algorithm:
- Load all the required libraries. Check
requirements.txt
for the versions. - Load the original image in the RGB color space.
- Convert the RGB space to HSV.
- Then, we create a Kx3 matrix by converting the MxNx3 image.
unit8
values are converted tofloat
.- Create cluster as per the requirement and criteria.
- Convert the converted
float
tounit8
. - Access the labels to regenerate the clustered image.
- Visualize the output result with K=10.
- Change the value of K as desired to see the noticeable changes in the output.
All the dependencies and required libraries are included in the file requirements.txt
See here
- Clone the project on your system.
- In the command line, run:
pip install -r requirements.txt
- Next, change the directory of the image to where you have cloned the project. (Comment mentioned in the code)
- Run the script;
python image_segmentation.py
to get the output.
- https://www.fritz.ai/image-segmentation/#part-basics
- https://towardsdatascience.com/image-segmentation-using-pythons-scikit-image-module-533a61ecc980
- https://www.javatpoint.com/k-means-clustering-algorithm-in-machine-learning
- https://www.geeksforgeeks.org/image-segmentation-using-k-means-clustering/