ImageOps.unsharp_mask不在PIL上工作

时间:2012-08-01 01:37:17

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

我在编写一个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那样做一些图像微调,并在控制质量等级的jpg中重新调整大小,旋转和导出。

1 个答案:

答案 0 :(得分: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