画像データにはカラー画像の24bit,32bit、モノクロ画像の8bit,16bitなどがありますが、Pillowで対応している画像データフォーマット(mode)の一覧は以下の通りです。
| mode | 説明 | 
| 1 | 1-bit pixels, black and white, stored with one pixel per byte | 
| L | 8-bit pixels, black and white | 
| P | 8-bit pixels, mapped to any other mode using a color palette | 
| RGB | 3×8-bit pixels, true color | 
| RGBA | 4×8-bit pixels, true color with transparency mask | 
| CMYK | 4×8-bit pixels, color separation | 
| YCbCr | 3×8-bit pixels, color video format | 
| LAB | 3×8-bit pixels, the L*a*b color space | 
| HSV | 3×8-bit pixels, Hue, Saturation, Value color space | 
| I | 32-bit signed integer pixels | 
| F | 32-bit floating point pixels | 
また、機能が限定的となりますが、以下のものも用意されています。
| LA | L with alpha | 
| PA | P with alpha | 
| RGBX | true color with padding | 
| RGBa | true color with premultiplied alpha | 
| La | L with premultiplied alpha | 
| I;16 | 16-bit unsigned integer pixels | 
| I;16L | 16-bit little endian unsigned integer pixels | 
| I;16B | 16-bit big endian unsigned integer pixels | 
| I;16N | 16-bit native endian unsigned integer pixels | 
| BGR;15 | 15-bit reversed true colour | 
| BGR;16 | 16-bit reversed true colour | 
| BGR;24 | 24-bit reversed true colour | 
| BGR;32 | 32-bit reversed true colour | 
(参考)

Concepts
The Python Imaging Library handles raster images; that is, rectangles of pixel data. Bands: An image can consist of one ...
一般的に用いられるのは、カラー24bitの RGB とモノクロ(グレースケール)8bitの L が多いと思います。
C言語やC#などでは、モノクロ画像の場合はカラーパレットを参照して表示するインデックスドカラーというのが標準的だったのですが、このインデックスドカラーに相当するのは P となります。
使用例
from PIL import Image
# PIL.Imageで画像を開く
img = Image.open("./Parrots.bmp")
print(img.mode)
img.show()  # 画像の表示
# カラー→モノクロ変換
gray = img.convert("L")
gray.show()  # 画像の表示
(実行結果)




コメント