1

我编写了一个 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 那样的图像 tweeksautocontrast以及unsharp_mask在控制质量水平的 jpg 中重新调整大小、旋转和导出的能力。

4

1 回答 1

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 质量如何在 Python 图像库中调整调整大小的图像的质量?

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

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

于 2012-08-01T03:59:06.227 回答