代码拉取完成,页面将自动刷新
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
# ?
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。