更改特定像素的颜色[棒] [英] Change color of specific pixels [Wand]
本文介绍了更改特定像素的颜色[棒]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在使用魔杖Python库来处理一些图像.
So, I'm using Wand Python Library to mess around with some images.
我只希望它逐个像素地查看图像,对于特定颜色的每个像素(例如"4d4d4d"),将该像素颜色替换为其他颜色,例如#00ff00".而已. 我已经对文档进行了彻底的搜索,但我终生无法弄清楚该怎么做.
I just want it to look at an image, pixel by pixel, and for each pixel that is a specific color, say '4d4d4d', replace that pixels color to something else, like '#00ff00'. That's it. I've thoroughly scoured the documentation and I can't for the life of me figure out how to do this.
推荐答案
如果有人感兴趣,那么python代码将是这样的:
If anyone is interested the python code would be something like this:
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
with Drawing() as draw:
draw.fill_color = Color('#00ff00')
draw.color(x,y,'replace')
with Image(filename='image.jpg') as img:
draw(img)
img.save(filename='new_image.jpg')
这篇关于更改特定像素的颜色[棒]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文