繁体   English   中英

使用 python wand 对图像进行灰度处理

[英]Use python wand to grayscale image

我想使用 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

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

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

进一步阅读:

这是正确的代码:

您需要转换色彩空间:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM