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のようないくつかの画像tweeksを実行しautocontrastunsharp_mask品質レベルを制御してjpgでサイズ変更、回転、エクスポートする機能。

4

1 に答える 1

1

必要なのは、画像とPILImageFilterモジュール[1]に対するfilterコマンドです。

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]の一部であり、同じ方法で適用されます。変換(回転、サイズ変更)は、画像オブジェクト自体、つまりimg.resizeでfunctions[2]を呼び出すことによって処理されます。この質問は、JPEG品質に対応しています。PythonImagingLibraryでサイズ変更された画像の品質を調整するにはどうすればよいですか?

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

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

于 2012-08-01T03:59:06.227 に答える