/k-means-image-segmentation

Implementation of k-means algorithm for image segmentation

Primary LanguagePython

License: MIT

Image segmentation using k-means algorithm

This repository contains program to perform image segmentation i.e. dividing the image into user-defined number of classes using k-means algorithm. The algorithm has been implemented from scratch without using any inbuilt cv2 function. The below image of "traffic signal" has been divided into 4 classes.

Requirement:

  • Python 2.0 or above

Dependencies:

  • OpenCV
  • NumPy

Instruction to run the code:

python k_means.py

Result

Fig. 1 - Original image                                Fig. 2 - Segmented image