KMeansImage
1.0.0
这是一个Python软件包,可使用KMeans群集技术在Python中压缩图像。
使用:
pip3 install KMeansImage
from KMeansImage import kmeans_image
k_img = kmeans_image( $image_path_with_image_name , $output_colors )
k_img.save( $save_path_with_file_name )
如果您使用Jupyter笔记本,也可以使用:
from KMeansImage import kmeans_image_ui
k_img = kmeans_image_ui( $image_directory_path )
k_img.save( $save_path_with_file_name )
导入库
from KMeansImage import kmeans_image第一个参数=路径
第二个参数=颜色数,即集群
k_img = kmeans_image ( '/home/sahil/Downloads/KMeansImage/res/batman.jpg' , 20 ) Original Image size: 419.291KB
Compressed Image: 253.235KB

看到这两张照片的大小之间的差异
用于保存文件使用 -
k_img . save () Image saved: /home/sahil/Downloads/KMeansImage/res/batman_KMeans_.jpg
from KMeansImage import kmeans_image_ui参数=图像目录路径
k_img = kmeans_image_ui ( '/home/sahil/Downloads/KMeansImage/res/' )
k_img . save () Image saved: /home/sahil/Downloads/KMeansImage/res/sherlock_KMeans_.jpg
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager
您也可以使用github下载:
pip install .
萨希尔
麻省理工学院
免费软件,地狱!