使用Wand替换颜色 [英] Replace a color using Wand

查看:292
本文介绍了使用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.

这是原始图片:

这里是代码:

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位于图像蓝色部分的中间位置。
现在应该是红色的,除了没有变化。
我想也许它与模糊有关但我无法弄清楚语法。我试过了:

192,84 is somewhere around the middle of the blue section of the image. 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.

所以我试过:

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)

这篇关于使用Wand替换颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆