
- 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 - 銳化蒙版濾鏡
- 影像增強和校正
- 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.invert() 函式
在 Python 影像處理庫 Pillow (PIL) 中,位於 ImageOps 模組中的 invert 函式提供了一種方便的方法來執行影像中畫素值的負正反轉。
此 PIL.ImageChops.invert 函式用於反轉影像或通道的畫素值。它透過從最大可能的畫素值中減去每個畫素值來計算反轉值。該操作實現如下:
$$\mathrm{out\:=\:MAX\:−\:image}$$
語法
以下是函式的語法:
PIL.ImageChops.invert(image)
引數
以下是此函式引數的詳細資訊:
image - 將反轉其畫素值的輸入影像。
返回值
此函式的返回型別為 Image。
示例
示例 1
這是一個使用 ImageChops.invert() 函式對 JPEG 影像檔案執行畫素值負正反轉的示例。
from PIL import Image, ImageChops # Open a PNG image file original_image = Image.open('Images/Car_2.jpg') # Invert the pixel values of the image inverted_image = ImageChops.invert(original_image) # Display the input and resulting images original_image.show() inverted_image.show()
輸出
輸入影像

輸出影像

示例 2
此示例演示了在將 ImageChops.invert() 應用於 BMP 型別輸入影像之前和之後畫素值。
from PIL import Image, ImageChops # Open an image file original_image = Image.open('Images/lena.bmp') # Display the pixel values before inversion print("Pixel values in the original image at (0, 0) before inversion:", original_image.getpixel((0, 0))) # Apply the ImageChops.invert() function to invert pixel values inverted_image = ImageChops.invert(original_image) # Display the pixel values after inversion print("Pixel values in the inverted image at (0, 0) after inversion:", inverted_image.getpixel((0, 0))) # Display the input and resulting images original_image.show() inverted_image.show()
輸出
輸入影像

輸出影像

示例 3
以下示例演示如何使用 ImageChops.invert() 函式對 RGB 影像的單個通道應用反轉操作。
from PIL import Image, ImageChops # Open an image file original_image = Image.open('Images/flowers.jpg') # Split the channels of the image red, green, blue = original_image.split() # Invert the green channel inverted_green_channel = ImageChops.invert(green) # Merge the channels back into an RGB image image_with_inverted_green = Image.merge('RGB', (red, inverted_green_channel, blue)) # Display the input and resulting images original_image.show() image_with_inverted_green.show()
輸出
輸入影像

輸出影像

python_pillow_function_reference.htm
廣告