Skip to content

rishabbahal9/ImageSeg-KMeans

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Image Segmentation using k-means clustering

The program reads in an image, segments it using K-Means clustering and outputs the segmented image.

python imageSegmentation.py K inputImageFilename outputImageFilename iterations

example: python imageSegmentation.py 3 output/tshirt.ppm output/tshirt_segmented.ppm 10

It is worth playing with the number of iterations, low numbers will run quicker.

The result is an over-segmented image. With the correct parameters, it can be used to partition an image for further processing. Here is an example of that: Make3D

Output

Burma Burma

Duomo Duoma

tunnel tunnel

cv2 is used only to accept image file of types .ppm an .pgm which are not supported by Image.open(inputName), whereas Logic behind kmeans is written in python and no library has been used.

If you wish you can still use image = Image.open(inputName) instead of

image = cv2.imread(inputName)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)

if you are not using .ppm and .pgm and only using .jpg

About

๐Ÿ’  Image Segmentation using K-Means

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%