猫史档案馆


【Python作品分享】图像转换器【作品秀】

用户:小电鼠vdc1小电鼠vdc1查看:0 回复:1 评论:0 创建时间:2021-04-02T21:46:47


【作品展示】

center_image

 

【作品介绍】

发一张图,把它变成像素方格

 

【作品源代码】

from PIL import Image
import matplotlib.pyplot as plt
import collections

pic = Image.open("BCM.png").convert("RGB")
width, hight = pic.size
block = 10

board = Image.new("RGB", (width//10*10, hight//10*10))
for y in range(0, hight, block):
    for x in range(0, width, block):
        temp = pic.crop((x, y, x+block, y+block))
        temp_list = list(temp.getdata())
        max_color = collections.Counter(temp_list).most_common()[0][0]
        temp_past = Image.new("RGB", temp.size, max_color)
        board.paste(temp_past, (x, y))
        #plt.imshow(oard)
        #plt.pause(0,01)
board.show()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
xwstsrhxwstsrh

用画图他不香吗

点赞0


评论