while max_iters > 0:
max_iters -= 1
for i in range(0len(clusters)):
cluster = clusters[i
# cacluate distance for each pixels in 2xS rectangle
for x in range(max(cluster.center.x-S0) min(cluster.center.x+Sheight)):
for y in range(max(cluster.center.y-S0) min(cluster.center.y+Swidth)):
pi = Pixel(lab[x
[y
[0
lab[x
[y
[1
lab[x
[y
[2
x y)
dis = cluster.distance(pi S M)
if dis < d[x
[y
:
d[x
[y
= dis
l[x
[y
= i
# assign pixels to best cluster
for cluster in clusters:
cluster.cleanup_pixels()
for x in range(0height):
for y in range(0width):
i = l[x
[y
pi = Pixel(lab[x
[y
[0
lab[x
[y
[1
lab[x
[y
[2
x y)
clusters[i
.assign(pi)
# update clusters
epsilon_t = 0
for cluster in clusters:
epsilon_t += cluster.update()
espilon /= len(clusters)
print (\"iteration step done %s remains with epsilon %s\"%(max_iters epsilon_t))
draw(lab height width clusters l max_iters)
保存图片
requirementspillow
def draw(lab height width clusters l ix):
for x in range(0height):
for y in range(0width):
i = l[x
[y
lab[x
[y
= clusters[i
.lab()
for i in range(0 len(clusters)):
x y = clusters[i
.center.x clusters[i
.center.y
lab[x
[y
= 0
rgb = color.lab2rgb(lab)
io.imsave(\"img/%i.jpg\"%ix rgb)
skimage
numpy
matploblib
附录不同于常用的 RGB 色彩空间 , 采用 CIELAB(国际照明委员会)色彩空间表示 , LAB的特点在于比RGB更为平滑 , 对肉眼视觉的感官衡量更为贴近 。 弥补了 RGB 与 CMYK 两种彩色模式的不足 , 是Photoshop用来从一种色彩模式向另一种色彩模式转换时使用的一种内部色彩模式 。 LAB模式也是由三个通道组成 , 分别是l , a , b , 其中I代表亮度 , 数值范围为 [0 100
, a表示从绿色到红色的分量 , 数值范围为[-128 127
, b表示蓝色到黄色的分量 , 数值范围为 [-128 127
。
- 雷军宣布小米13系列将很快登陆全球市场:国外用户激动坏了在中国市场发布后|雷军宣布小米13系列很快登陆全球市场:国外用户激动坏了
- 腾讯云智能打法首揭秘!4条快速路让AI“开箱即用”
- 虚假宣传?特斯拉被勒令免费升级自动驾驶硬件:老用户狂喜
- 近日|余承东:没有5G,我们用4G增强+WIFI 6来弥补
- “通信行程卡”12月13日下线!中国信通院、三大运营商同步删除用户数据
- 终于有人用 AIGC「干正事」了—— 设计蛋白质
- OPPO|OPPO二代自研芯片马里亚纳Y亮相:蓝牙耳机专用
- 贝尔金推出了一款65W双口氮化镓充电器|一款小小充电器近300元用料如何?贝尔金65W氮化镓快充拆解
- 苹果|iPad 10耐用性测试:惨遭一掰两半!质量堪忧
- 宽带|全球第一次:万兆家用宽带成了!上传、下载都是几千兆
