[英]Replace a color using Wand
我正在嘗試通過定義其像素之一的坐標來用另一種顏色替換圖像中的一種顏色。 但是,當我運行代碼時,結果與原始代碼完全相同。
這是原始圖片:
這是代碼:
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
我沒有錯誤,但是圖像仍然沒有變化。
我猜您沒有將繪圖上下文應用於圖像。
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.