【问题标题】:ImageOps.unsharp_mask not working on PILImageOps.unsharp_mask 不适用于 PIL
【发布时间】:2012-08-01 01:37:16
【问题描述】:

我正在编写一个 Python 应用程序,我需要在其中执行一些图像任务。

我正在尝试 PIL,它是 ImageOps 模块。但看起来 unsharp_mask 方法不能正常工作。它应该返回另一个图像,但正在返回一个 ImagingCore 对象,我不知道它是什么。

这里有一些代码:

import Image
import ImageOps

file = '/home/phius/test.jpg'
img = Image.open(file)
img = ImageOps.unsharp_mask(img)
#This fails with AttributeError: save
img.save(file)

我被困在这个问题上。

我需要什么:能够像 PIL 的 autocontrastunsharp_mask 那样做一些图像 tweeks,并在控制质量级别的 jpg 中重新调整大小、旋转和导出。

【问题讨论】:

    标签: python image-processing python-imaging-library imagefilter


    【解决方案1】:

    您想要的是图像上的过滤命令和 PIL ImageFilter 模块[1] 所以:

    import Image
    import ImageFilter
    
    file = '/home/phius/test.jpg'
    img = Image.open(file)
    img2 = img.filter(ImageFilter.UnsharpMask) # note it returns a new image
    img2.save(file)
    

    其他过滤操作也是 ImageFilter 模块[1] 的一部分,应用方式相同。变换(旋转、调整大小)是通过调用图像对象本身的函数 [2] 来处理的,即 img.resize。这个问题解决了JPEG质量How to adjust the quality of a resized image in Python Imaging Library?

    [1]http://effbot.org/imagingbook/imagefilter.htm

    [2]http://effbot.org/imagingbook/image.htm

    【讨论】:

    • 非常感谢你,罗里。我已经在做的其他事情(旋转,保存质量),只是发布以防有人建议另一个库。 =)
    猜你喜欢
    • 2014-06-28
    • 2013-09-26
    • 1970-01-01
    • 2013-11-10
    • 2021-07-07
    • 2012-07-28
    • 1970-01-01
    • 2020-04-30
    • 2012-12-20
    相关资源
    最近更新 更多