简体   繁体   English

使用魔杖替换颜色

[英]Replace a color using Wand

I'm trying to replace a color in an image with another color, by defining the coordinates of one of its pixels. 我正在尝试通过定义其像素之一的坐标来用另一种颜色替换图像中的一种颜色。 But when I run the code the result is exactly the same as the original. 但是,当我运行代码时,结果与原始代码完全相同。

here's the original image: 这是原始图片:

here's the code: 这是代码:

from wand.image import Image
from wand.display import display
from wand.drawing import Drawing
from wand.color import Color

with Drawing() as draw:
    draw.fill_color = Color('#ff0000')
    draw.color(192,84,'replace')

    with Image(filename='rgb.jpg') as img:
        img.save(filename='rgr.jpg')
        display(img)

192,84 is somewhere around the middle of the blue section of the image. 192,84在图像蓝色部分的中间。 Which should now be red, except nothing changes. 现在应该是红色的,除非没有任何变化。 I thought maybe it has something to do with the "fuzz" but i can't figure out the syntax. 我以为可能与“模糊”有关,但我不知道语法。 I tried: 我试过了:

draw.color(192,84,'replace',fuzz=10)

But I got the "unexpected keyword argument 'fuzz'" error. 但是我收到“意外的关键字参数'fuzz'”错误。

so I tried: 所以我尝试了:

draw.fuzz = 10

I got no errors, but the image still had no change. 我没有错误,但是图像仍然没有变化。

I would guess that you did not apply the drawing context to the image. 我猜您没有将绘图上下文应用于图像。

from wand.image import Image
from wand.display import display
from wand.drawing import Drawing
from wand.color import Color

with Drawing() as draw:
    draw.fill_color = Color('#ff0000')
    draw.color(192,84,'replace')

    with Image(filename='gb.jpg') as img:
        draw(img)  # <= here
        img.save(filename='rgr.jpg')
        display(omg)

使用魔杖替换颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM