python将图像变成没有颜色_Python将图像转换为使用较少的颜色

Library (libraries) to use?

scikit-image或{a2}将是我的首选。在Methods? (Are there any widely used algorithms for this kind of problem?)Am I using the wrong programming language? (Is there one that offers this kind of functionality but easier to use?)

Python可以说是这个任务的“最简单”语言。在

演示

考虑一下这个图像:

QCl8D.jpg

仅将以下代码从6+500K减少为:import numpy as np

from skimage import io

from sklearn.cluster import KMeans

original = io.imread('https://i.stack.imgur.com/QCl8D.jpg')

n_colors = 6

arr = original.reshape((-1, 3))

kmeans = KMeans(n_clusters=n_colors, random_state=42).fit(arr)

labels = kmeans.labels_

centers = kmeans.cluster_centers_

less_colors = centers[labels].reshape(original.shape).astype('uint8')

io.imshow(less_colors)

这就是彩色量化图像的外观:

kvIHW.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值