A K-Means based image compressor. Consists interactive widgets for Jupyter Notebook
Project description
KMeansImage
Pip package(Python >= 3.6)
This is a python package to compress images in python using KMeans-Clustering technique.
Download the package using:
pip3 install KMeansImage
How to use:
from KMeansImage import kmeans_image
k_img = kmeans_image( $image_path_with_image_name , $output_colors )
k_img.save( $save_path_with_file_name )
In case you are using Jupyter notebook, you can also use:
from KMeansImage import kmeans_image_ui
k_img = kmeans_image_ui( $image_directory_path )
k_img.save( $save_path_with_file_name )
Example: Pdf
Import Library
from KMeansImage import kmeans_image
First parameter = path
Second parameter = No. of colors i.e. Clusters
k_img = kmeans_image('/home/sahil/Downloads/KMeansImage/res/batman.jpg', 20)
Original Image size: 419.291KB
Compressed Image: 253.235KB
See the difference between size of both pics
For saving the file use -
k_img.save()
Image saved: /home/sahil/Downloads/KMeansImage/res/batman_KMeans_.jpg
Interactive For Jupyter Notebook
from KMeansImage import kmeans_image_ui
Parameter = Image directory path
k_img = kmeans_image_ui('/home/sahil/Downloads/KMeansImage/res/')
k_img.save()
Image saved: /home/sahil/Downloads/KMeansImage/res/sherlock_KMeans_.jpg
Jupyter Notebook Dependency:
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager
You can also download using Github:
- Download and extract this repo
- Move the terminal to the directory of setup.py
pip install .
Packages Required:
- numpy
- scikit-learn
- matplotlib
- ipywidgets
Contact Me:
Todos
- Add a button for saving images instead of save() in interactive notebook
- Add some boundary conditions
- Add Test cases
License
MIT
Free Software, Hell Yeah!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
KMeansImage-1.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for KMeansImage-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ed346865a3a4db6dfc3301bd0b4332f7d140759881db4e9654ca442938e38f |
|
MD5 | 78efa15da94c2a8d01f1788ac0d9af56 |
|
BLAKE2b-256 | 1e9112f2c032a4605d848f22db4291de285575d09ab9d025652500ee6766b56c |