2015-11-28 40 views
1

我試圖用另一種顏色替換圖像中的顏色,方法是定義其中一個像素的座標。 但是,當我運行代碼的結果是完全一樣的原始。使用魔杖替換顏色

這裏的原始圖像:

下面的代碼:

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是圍繞圖像中的藍色部分的中間位置。 現在應該是紅色的,除了沒有變化。 我想也許它與「模糊」有關,但我無法弄清楚語法。我試過了:

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

但是我得到了「意外的關鍵字參數'fuzz'」錯誤。

所以我嘗試:

draw.fuzz = 10 

我沒有錯誤,但圖像仍然沒有改變。

回答

1

我猜你沒有將圖形上下文應用到圖像上。

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) 

Replace a color using Wand

+0

我無法相信我錯過了。謝謝。 – serisAK