
- Python Pillow 教程
- Python Pillow - 首頁
- Python Pillow - 概述
- Python Pillow - 環境設定
- 基本影像操作
- Python Pillow - 影像處理
- Python Pillow - 調整影像大小
- Python Pillow - 翻轉和旋轉影像
- Python Pillow - 裁剪影像
- Python Pillow - 為影像新增邊框
- Python Pillow - 識別影像檔案
- Python Pillow - 合併影像
- Python Pillow - 剪下和貼上影像
- Python Pillow - 滾動影像
- Python Pillow - 在影像上新增文字
- Python Pillow - ImageDraw 模組
- Python Pillow - 合併兩張影像
- Python Pillow - 建立縮圖
- Python Pillow - 建立水印
- Python Pillow - 影像序列
- Python Pillow 顏色轉換
- Python Pillow - 影像上的顏色
- Python Pillow - 使用顏色建立影像
- Python Pillow - 將顏色字串轉換為 RGB 顏色值
- Python Pillow - 將顏色字串轉換為灰度值
- Python Pillow - 透過更改畫素值來更改顏色
- 影像處理
- Python Pillow - 降噪
- Python Pillow - 更改影像模式
- Python Pillow - 影像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 應用透視變換
- 影像濾鏡
- Python Pillow - 為影像新增濾鏡
- Python Pillow - 卷積濾鏡
- Python Pillow - 模糊影像
- Python Pillow - 邊緣檢測
- Python Pillow - 浮雕影像
- Python Pillow - 增強邊緣
- Python Pillow - Unsharp Mask 濾鏡
- 影像增強和校正
- Python Pillow - 增強對比度
- Python Pillow - 增強銳度
- Python Pillow - 增強色彩
- Python Pillow - 校正色彩平衡
- Python Pillow - 去噪
- 影像分析
- Python Pillow - 提取影像元資料
- Python Pillow - 識別顏色
- 高階主題
- Python Pillow - 建立動畫 GIF
- Python Pillow - 批次處理影像
- Python Pillow - 轉換影像檔案格式
- Python Pillow - 為影像新增填充
- Python Pillow - 顏色反轉
- Python Pillow - 使用 NumPy 進行機器學習
- Python Pillow 與 Tkinter BitmapImage 和 PhotoImage 物件
- Image 模組
- Python Pillow - 影像混合
- Python Pillow 有用資源
- Python Pillow - 快速指南
- Python Pillow - 函式參考
- Python Pillow - 有用資源
- Python Pillow - 討論
Python Pillow - ImageChops.screen() 函式
Python 影像處理庫 Pillow (PIL) 的 ImageChops 模組提供了一系列函式,用於對影像執行算術運算。除了這些運算之外,該模組還提供專門為影像混合模式運算設計的函式。這些混合模式之一就是螢幕模式。
PIL 中的 ImageChops.screen 函式使用螢幕混合模式將兩張反轉的影像疊加在一起。
該運算定義如下:
$$\mathrm{out\:=\:MAX\:-\:((MAX\:-\:image1)\:*\:(MAX\:-\:image2)\:/\:MAX)}$$
語法
以下是該函式的語法:
PIL.ImageChops.screen(image1, image2)
引數
以下是此函式引數的詳細資訊:
image1 - 第一個模式為“1”的輸入二值影像。
image2 - 第二個模式為“1”的輸入二值影像。
返回值
此函式的返回型別為 Image。
示例
示例 1
這是另一個示例,演示了 ImageChops.screen() 函式將兩張反轉的影像疊加在一起的工作方式。
from PIL import Image, ImageChops import numpy as np # Create the two input images using numpy arrays array1 = np.array([(154, 64, 3), (255, 0, 0), (255, 255, 0), (255, 255, 255), (164, 0, 3)], dtype=np.uint8) array2 = np.array([(200, 14, 3), (20, 222, 0), (255, 155, 0), (255, 55, 100), (180, 0, 78)], dtype=np.uint8) image1 = Image.fromarray(array1) image2 = Image.fromarray(array2) # Display the pixel values of the two input images print("Pixel values of image1 at (0, 0):", image1.getpixel((0, 0))) print("Pixel values of image2 at (0, 0):", image2.getpixel((0, 0))) # Additionally, demonstrate the use of the screen blend mode result_screen = ImageChops.screen(image1, image2) # Display the pixel values of the resulting image at (0, 0) after screen blend mode print("Pixel values of the result at (0, 0) after screen blend mode:", result_screen.getpixel((0, 0)))
輸出
Pixel values of image1 at (0, 0): 154 Pixel values of image2 at (0, 0): 200 Pixel values of the result at (0, 0) after screen blend mode: 234
示例 2
在此示例中,PIL.ImageChops.screen() 函式應用於兩張 PNG 影像,以將兩張反轉的影像疊加在一起。
from PIL import Image, ImageChops # Open the two image files image1 = Image.open("Images/pillow-logo-w.png") image2 = Image.open("Images/ColorDots.png") # Apply the Screen algorithm result = ImageChops.screen(image1, image2) # Display the input and resulting images image1.show() image2.show() result.show()
輸出
輸入影像 1

輸入影像 2

輸出影像

示例 3
這是另一個示例,它將 PIL.ImageChops.overlay() 函式應用於兩張 JPEG 影像。
from PIL import Image, ImageChops # Open the two image files image1 = Image.open("Images/Tajmahal_2.jpg") image2 = Image.open("Images/Flower1.jpg") # Apply the Screen algorithm result = ImageChops.screen(image1, image2) # Display the input and resulting images image1.show() image2.show() result.show()
輸出
輸入影像 1

輸入影像 2

輸出影像

python_pillow_function_reference.htm
廣告