【问题标题】:Use python wand to grayscale image使用 python wand 对图像进行灰度化
【发布时间】:2013-04-15 06:53:19
【问题描述】:

我想使用 ImageMagick http://wand-py.org 的 Python API 绑定来直接操作图像。但是,我无法从文档中推断出如何使用灰度转换。任何人都可以提供有关此问题的信息吗?

from wand.image import Image
try:
  with Image(file=path) as img:
    img.grayscale() # PSEUDOCODE for my given problem
except:
  pass

【问题讨论】:

    标签: python imagemagick grayscale magickwand wand


    【解决方案1】:

    这可以通过设置图像的色彩空间来实现。

    from wand.image import Image
    with Image(filename='color.jpg') as img:
        img.type = 'grayscale';
        img.save(filename='grayscale.jpg');
    

    进一步阅读:

    【讨论】:

      【解决方案2】:

      这是正确的代码:

      您需要转换色彩空间:

        with Image(filename=str(f)) as img:
              img.transform_colorspace('gray')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-04
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        • 2015-04-15
        相关资源
        最近更新 更多