Skip to content

adarsh98261/Image-segmentation-using-K-Means

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Image Segmentation using K-Means Clustering

This project demonstrates image segmentation using K-Means clustering. The code resizes the input images, applies K-Means clustering to segment the images into different regions, and computes the silhouette score to evaluate the quality of the clusters.

Table of Contents

Introduction

Image segmentation is the process of partitioning an image into multiple segments or clusters to simplify or change the representation of an image into something more meaningful and easier to analyze. In this project, we use the K-Means clustering algorithm to achieve image segmentation. The K-Means algorithm partitions the image pixels into k clusters based on their color similarity.

Installation

To run this project, you need to have Python installed along with the following libraries:

  • numpy
  • opencv-python
  • scikit-learn
  • matplotlib

You can install these dependencies using pip:

pip install numpy opencv-python scikit-learn matplotlib

Usage

  1. Clone the repository:

    git clone https://github.com/yourusername/image-segmentation-kmeans.git
    cd image-segmentation-kmeans
  2. Place your images in a directory, e.g., images/.

  3. Update the image_paths list in the script with the paths to your images:

    image_paths = ["images/image1.jpg", "images/image2.jpg"]
  4. Run the script:

    python segment_images.py

Results

The script will output the original and clustered images side by side, along with the silhouette score for each clustered image. The silhouette score indicates how well each pixel has been clustered.

Example Output

  1. download
  2. download (1)
  3. download (2)

References

About

Using K-Means clustering segmenting the images based on given k clusters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published