使用Python的Wand库将图像转为灰度图片

10

我希望使用Python对图像进行直接操作,因此想要使用ImageMagick的Python API绑定(http://wand-py.org)。然而,我无法从文档中推断出如何使用灰度转换。是否有人可以提供有关此问题的信息?

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

20

1

这是正确的代码:

您需要转换颜色空间:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接