2

私は画像処理スクリプト(ライブラリを使用)に取り組んでおり、画像PythonPIL色空間を に変換する必要がありますRGB。このトリックを試しましたが、色空間pngの画像でのみ機能します。RGBa

image = Image.open(imageFile)
image.load()

# replace alpha channel with white color
self.im = Image.new('RGB', image.size, (255, 255, 255))
self.im.paste(image, mask=image.split()[3])

このコードを任意の色空間のすべての画像に普遍的に作成する方法は?

ありがとう。

4

2 に答える 2

1

見つかった解決策:

image = Image.open(imageFile)
image.load()

# replace alpha channel with white color
self.im = Image.new('RGB', image.size, (255, 255, 255))
self.im.paste(image, None)

変数には、self.im白 (255, 255, 255) アルファ チャネルを持つ RGB 色空間の画像が格納されます。

于 2013-04-12T11:59:46.087 に答える
0

PIL のみを使用しますか? openCV バージョン 2 python バインディングをお勧めしますcv2

http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cv2.cvtColor

最も一般的な色空間の間で多くの変換が可能です。

あなたがしたくないopenCV場合は、使用することができますskimage

http://scikit-image.org/docs/dev/api/skimage.color.html#convert-colorspace

于 2013-04-11T11:37:54.620 に答える