1 Star 0 Fork 0

kangchi/Depix

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
genpixed.py 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
from depixlib.LoadedImage import *
from depixlib.Rectangle import *
from depixlib.functions import *
import argparse
import logging
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--image', help = 'Path to image to pixelize', required=True)
parser.add_argument('-o', '--outputimage', help = 'Path to output image', nargs='?', default='output.png')
args = parser.parse_args()
imagePath = args.image
image = LoadedImage(imagePath)
outputImage = image.getCopyOfLoadedPILImage()
blockSize = 5
blockPixelCount = blockSize * blockSize
for x in range(0, image.width, blockSize):
for y in range(0, image.height, blockSize):
r = g = b = 0
maxX = min(x+blockSize, image.width)
maxY = min(y+blockSize, image.height)
for xx in range(x, maxX):
for yy in range(y, maxY):
currentPixel = image.imageData[xx][yy]
r += currentPixel[0]
g += currentPixel[1]
b += currentPixel[2]
averageR = int(r / blockPixelCount)
averageG = int(g / blockPixelCount)
averageB = int(b / blockPixelCount)
averageColor = (averageR, averageG, averageB)
for xx in range(x, maxX):
for yy in range(y, maxY):
outputImage.putpixel((xx,yy), averageColor)
outputImage.save(args.outputimage)
# Generated:
# 676c81
# Gimp:
# 878a9e
# diff: 2104861
# Generated:
# 889475
# Gimp:
# a7b194
# diff: 2039071
# ?
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kangchi/Depix.git
git@gitee.com:kangchi/Depix.git
kangchi
Depix
Depix
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385