gpt4 book ai didi

c++ - 读取图像并用最接近的颜色近似和重建每个像素?

转载 作者:行者123 更新时间:2023-11-28 03:50:06 25 4
gpt4 key购买 nike

http://pastebin.com/v0B3Vje2我正在寻找一种从图像中获取像素的方法,然后找到与另一个程序中的像素最接近的颜色(我可以将其编译到“另一个程序”的源代码中;如果兼容而无需源注入(inject)则完美)然后使用它颜色并将其放入正确的像素。基本上,Script/Code/Executable 以图像文件为例,然后重新创建具有最接近匹配的每个像素。我正在谈论的节目是 The Powder Toy。 (powdertoy.co.uk)。如果您知道的话,我将它用于私有(private)目的和概念验证,因为“公共(public)保存”中不能包含 CGI。 JoJoBond 是那里的用户之一,他/她首先这样做,因此被允许这样做。

最佳答案

您可以使用 Python Imaging Library加载图像并提取像素颜色值:

import Image

img = Image.open('random.png')
width, height = img.size
pixels = img.getdata()
print 'pixels:'
for i, px in enumerate(img.getdata()):

# decide whether to replace this pixel

# call out to external program to translate color value
r, g, b = px
npx = (b, g, r)

# replace pixel with new color value
y = i / width
x = i % width
img.putpixel((x, y), npx)

print px, npx

输出:

pixels:
(58, 0, 0) (0, 0, 58)
(0, 0, 0) (0, 0, 0)
(0, 0, 4) (4, 0, 0)
(0, 0, 0) (0, 0, 0)
(0, 0, 0) (0, 0, 0)
(0, 245, 0) (0, 245, 0)
(0, 0, 0) (0, 0, 0)
(0, 0, 0) (0, 0, 0)
(14, 0, 0) (0, 0, 14)
...

关于c++ - 读取图像并用最接近的颜色近似和重建每个像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5819087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com