簡體   English   中英

Python Wand vs imagemagick亮度對比命令

[英]Python Wand vs imagemagick brightness-contrast command

我嘗試使用Wand,但找不到亮度對比命令的任何映射。

來源img

  • 嘗試使用調制來更改亮度:

    value = 100 + value # no changes = 0 in console and 100 in wand img.modulate(brightness=value)

我得到了一些帶有白色像素的奇怪偽像: 嘗試改變亮度

  • 為了使用對比度,魔杖只有contrast_stretch(),我不明白該怎么做

    convert '-brightness-contrast 0x%d'

幸運的是, -brightness-contrast只是調用在實現的-function Polynomial方法。 需要一些非常簡單的數學運算將brightness x contrast參數轉換為slop x intercept

import math
from wand.image import Image

class MyImage(Image):
    def brightness_contrast(self, brightness=0.0, contrast=0.0):
        slope=math.tan((math.pi * (contrast/100.0+1.0)/4.0))
        if slope < 0.0:
          slope=0.0
        intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope)
        self.function("polynomial", [slope, intercept])

with MyImage(filename="rose:") as img:
    img.brightness_contrast(0.0, 10.0)
    img.save(filename="rose.png")

rose.png

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM