1

我正在编写一个Python应用程序,我需要执行一些图像任务。ImageOps.unsharp_mask在PIL上不工作

我在尝试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

你需要的是你的图像上的过滤器命令和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

+0

非常感谢你,罗里。其他的事情(旋转,保存质量)我已经在做,只是张贴,以防有人抢夺另一个图书馆。 =) – Phius 2012-08-01 04:32:25