[python]代码库
from PIL import Image
import collections
pic = Image.open("img.png").convert("RGB")
width, height = pic.size
block = 10 # 小格子大小,数字越大像素粒越大
board = Image.new("RGB", (width // block * block, height // block * block)) # 新图片宽高取整
for y in range(0, height, block): # 行
for x in range(0, width, block): # 列
temp = pic.crop((x, y, x + block, y + block)) # 截取block * block区块图像
temp_list = list(temp.getdata()) # 获取像素序列并转为普通序列
max_color = collections.Counter(temp_list).most_common()[0][0] # 计算像素块颜色,取最多出现的一个颜色
temp_past = Image.new("RGB", (block - 1, block - 1), max_color)
#temp_past = Image.new("RGB", (block, block), max_color) # 像素块无边框
board.paste(temp_past, (x, y))
x = x + block # 跳过
y = y + block # 跳过
board.show()
[代码运行效果截图]