k-means cluster images

时间:2023-03-08 20:01:23

说明

慕课网上例子,使用k-means算法分类图片, 此处调试运行通过, 并添加包管理内容, 使得其他同学容易运行。

例子地址: https://github.com/fanqingsong/cluster-images

运行环境:

python3.7

包管理工具:

pipenv

参考: https://www.cnblogs.com/wuzdandz/p/9545584.html

运行:

pipenv install

pipenv run ImageKmean.py

安装运行遇到问题

1、 安装依赖(numpy Pillow)很慢,

使用国内镜像替换:

http://greyli.com/set-custom-pypi-mirror-url-for-pip-pipenv-poetry-and-flit/

如果想对项目全局(per-project)设置,可以修改 Pipfile 中 [[source]] 小节:

[[source]]
url = "https://pypi.doubanio.com/simple"
verify_ssl = true
name = "douban"
1
2
3
4
5
[[source]]
url = "https://pypi.doubanio.com/simple"
verify_ssl = true
name = "douban"

如果不用pipenv, 使用pip安装

https://blog.****.net/lambert310/article/details/52412059

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple

运行结果

输入为 三张红花 和 三张黄花

聚类输入参数为2类

分类结果为 黄花一类  红花一类

k-means cluster images

类一

k-means cluster images

类二

k-means cluster images

运行报错: ModuleNotFoundError: No module named 'PIL'

https://blog.****.net/qq_37721412/article/details/79159544

pip install Pillow

Pillow库

https://pillow.readthedocs.io/en/stable/handbook/overview.html

he Python Imaging Library adds image processing capabilities to your Python interpreter.

This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities.

The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.

Let’s look at a few possible uses of this library.

参考

https://github.com/jump1003/ImageKmeans

https://scikit-learn.org/stable/auto_examples/index.html#general-examples