ImageChops
(“チャンネル操作”) モジュール¶
ImageChops
モジュールには、チャンネル操作(「chops」)と呼ばれる、多数の算術的な画像操作が含まれています。これらは、特殊効果、画像合成、アルゴリズムによるペイントなど、さまざまな目的に使用できます。
より多くの既製操作については、ImageOps
を参照してください。
現在、ほとんどのチャンネル操作は、8ビット画像(「L」や「RGB」など)でのみ実装されています。
関数¶
ほとんどのチャンネル操作は、1つまたは2つの画像引数を取り、新しい画像を返します。特に断りのない限り、チャンネル操作の結果は常に0からMAXの範囲(このモジュールの操作でサポートされているすべてのモードでは255)にクリップされます。
- PIL.ImageChops.add(image1: Image, image2: Image, scale: float = 1.0, offset: float = 0) Image [ソース]¶
2つの画像を追加し、結果をスケールで割り、オフセットを加えます。省略した場合、scaleはデフォルトで1.0、offsetは0.0になります。
out = ((image1 + image2) / scale + offset)
- 戻り値の型:
- PIL.ImageChops.add_modulo(image1: Image, image2: Image) Image [ソース]¶
結果をクリップせずに2つの画像を追加します。
out = ((image1 + image2) % MAX)
- 戻り値の型:
- PIL.ImageChops.blend(image1: Image, image2: Image, alpha: float) Image [ソース]¶
一定の透明度を使用して画像をブレンドします。
PIL.Image.blend()
のエイリアス。- 戻り値の型:
- PIL.ImageChops.composite(image1: Image, image2: Image, mask: Image) Image [ソース]¶
透明マスクを使用して合成を作成します。
PIL.Image.composite()
のエイリアス。- 戻り値の型:
- PIL.ImageChops.darker(image1: Image, image2: Image) Image [ソース]¶
2つの画像をピクセルごとに比較し、暗い値を含む新しい画像を返します。
out = min(image1, image2)
- 戻り値の型:
- PIL.ImageChops.difference(image1: Image, image2: Image) Image [ソース]¶
2つの画像間のピクセルごとの差の絶対値を返します。
out = abs(image1 - image2)
- 戻り値の型:
- PIL.ImageChops.duplicate(image: Image) Image [ソース]¶
チャンネルをコピーします。
PIL.Image.Image.copy()
のエイリアスです。- 戻り値の型:
- PIL.ImageChops.lighter(image1: Image, image2: Image) Image [ソース]¶
2つの画像をピクセルごとに比較し、より明るい値を含む新しい画像を返します。
out = max(image1, image2)
- 戻り値の型:
- PIL.ImageChops.logical_and(image1: Image, image2: Image) Image [ソース]¶
2つの画像間の論理AND。
両方の画像はモードが "1" である必要があります。"1" 以外のモードの画像で論理ANDを実行したい場合は、代わりに
multiply()
を、2番目の画像として白黒マスクを使用して試してください。out = ((image1 and image2) % MAX)
- 戻り値の型:
- PIL.ImageChops.logical_or(image1: Image, image2: Image) Image [ソース]¶
2つの画像間の論理OR。
両方の画像はモードが "1" である必要があります。
out = ((image1 or image2) % MAX)
- 戻り値の型:
- PIL.ImageChops.logical_xor(image1: Image, image2: Image) Image [ソース]¶
2つの画像間の論理XOR。
両方の画像はモードが "1" である必要があります。
out = ((bool(image1) != bool(image2)) % MAX)
- 戻り値の型:
- PIL.ImageChops.multiply(image1: Image, image2: Image) Image [ソース]¶
2つの画像を重ねて表示します。
画像を真っ黒な画像で乗算すると、結果は黒になります。真っ白な画像で乗算すると、画像は影響を受けません。
out = image1 * image2 / MAX
- 戻り値の型:
- PIL.ImageChops.soft_light(image1: Image, image2: Image) Image [ソース]¶
ソフトライトアルゴリズムを使用して、2つの画像を重ねて表示します。
- 戻り値の型:
- PIL.ImageChops.hard_light(image1: Image, image2: Image) Image [ソース]¶
ハードライトアルゴリズムを使用して、2つの画像を重ねて表示します。
- 戻り値の型:
- PIL.ImageChops.overlay(image1: Image, image2: Image) Image [ソース]¶
オーバーレイアルゴリズムを使用して、2つの画像を重ねて表示します。
- 戻り値の型:
- PIL.ImageChops.offset(image: Image, xoffset: int, yoffset: int | None = None) Image [ソース]¶
指定された距離だけデータがオフセットされた画像のコピーを返します。データはエッジの周りを折り返します。
yoffset
が省略された場合、xoffset
と等しいと見なされます。- パラメーター:
image – 入力画像。
xoffset – 水平方向の距離。
yoffset – 垂直方向の距離。省略した場合、両方の距離は同じ値に設定されます。
- 戻り値の型:
- PIL.ImageChops.screen(image1: Image, image2: Image) Image [ソース]¶
2つの反転した画像を重ね合わせます。
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
- 戻り値の型: