【问题标题】:Python Wand vs imagemagick brightness-contrast commandPython Wand vs imagemagick 亮度对比度命令
【发布时间】:2017-05-31 20:47:49
【问题描述】:

我尝试使用 Wand,但找不到亮度对比度命令的任何映射。

source img

  • 尝试使用调制来改变亮度:

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

我得到了一些带有白色像素的奇怪伪影: brightness change attempt

  • 为了使用对比度 Wand 只有 contrast_stretch(),我不明白如何做这样的事情

    convert '-brightness-contrast 0x%d'

【问题讨论】:

    标签: python imagemagick wand


    【解决方案1】:

    幸运的是,-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")
    

    【讨论】:

    • 非常简单:) 是的,它有效,但我不明白如何。然而 imagemagick 对我来说也是黑盒。我只是不明白为什么 Wand 开发人员没有在 shell 中创建类似的 API。
    • 作为解释,如果您想将亮度提高 10%,请使用等效的 ImageMagick -modulate(110,100,100)。但是你似乎想改变对比度而不是最亮的。您可以使用等效的 -level 0x90% 或 +level 0x110% 来做到这一点。在线性模式下使用 -function 多项式的等效项,您有两个参数 a 和 b,它们等效于斜率和截距。斜率控制对比度,截距控制亮度。
    • 绝对! Image.modulate & Image.level 存在于 wand 库中。
    • 伙计们,非常感谢您的回答。我还有一个关于 Wand/Imagemagick 的问题,你能看看吗? stackoverflow.com/questions/44327442/…
    猜你喜欢
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多