ImageChops
(「通道運算」) 模組¶
ImageChops
模組包含許多算術影像運算,稱為通道運算(「chops」)。這些運算可用於各種用途,包括特殊效果、影像合成、演算法繪畫等等。
如需更多預先製作的運算,請參閱 ImageOps
。
目前,大多數通道運算僅適用於 8 位元影像(例如「L」和「RGB」)。
函式¶
大多數通道運算會接收一個或兩個影像引數,並傳回一個新的影像。除非另有說明,否則通道運算的結果始終會被裁剪到 0 到 MAX 的範圍(對於此模組中運算支援的所有模式,MAX 為 255)。
- PIL.ImageChops.add(image1: Image, image2: Image, scale: float = 1.0, offset: float = 0) Image [原始碼]¶
將兩個影像相加,將結果除以縮放比例並加上偏移量。如果省略,則縮放比例預設為 1.0,而偏移量預設為 0.0。
out = ((image1 + image2) / scale + offset)
- 傳回型別:
- PIL.ImageChops.add_modulo(image1: Image, image2: Image) Image [原始碼]¶
將兩個影像相加,但不裁剪結果。
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 [原始碼]¶
逐像素比較兩張圖片,並返回一張包含較暗值的新圖片。
out = min(image1, image2)
- 傳回型別:
- PIL.ImageChops.difference(image1: Image, image2: Image) Image [原始碼]¶
返回兩張圖片之間逐像素差異的絕對值。
out = abs(image1 - image2)
- 傳回型別:
- PIL.ImageChops.lighter(image1: Image, image2: Image) Image [原始碼]¶
逐像素比較兩張圖片,並返回一張包含較亮值的新圖片。
out = max(image1, image2)
- 傳回型別:
- PIL.ImageChops.logical_and(image1: Image, image2: Image) Image [原始碼]¶
兩張圖片之間的邏輯 AND 運算。
兩張圖片的模式必須為 “1”。 如果您想在模式不是 “1” 的圖片上執行邏輯 AND 運算,請嘗試使用
multiply()
,並將黑白遮罩作為第二張圖片。out = ((image1 and image2) % MAX)
- 傳回型別:
- PIL.ImageChops.logical_or(image1: Image, image2: Image) Image [原始碼]¶
兩張圖片之間的邏輯 OR 運算。
兩張圖片的模式必須為 “1”。
out = ((image1 or image2) % MAX)
- 傳回型別:
- PIL.ImageChops.logical_xor(image1: Image, image2: Image) Image [原始碼]¶
兩張圖片之間的邏輯 XOR 運算。
兩張圖片的模式必須為 “1”。
out = ((bool(image1) != bool(image2)) % MAX)
- 傳回型別:
- PIL.ImageChops.multiply(image1: Image, image2: Image) Image [原始碼]¶
將兩張圖片疊加在一起。
如果將一張圖片與純黑色圖片相乘,結果將為黑色。如果與純白色圖片相乘,則圖片不受影響。
out = image1 * image2 / MAX
- 傳回型別:
- 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 [原始碼]¶
將兩個反轉的影像疊加在一起。
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
- 傳回型別: