
- 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 - 增強對比度
增強對比度是指提高影像可見性和質量的過程。這是一種影像處理技術,透過調整強度值或顏色的分佈,來增加影像中各種元素(如物體、形狀、邊緣和紋理)之間的差異。此技術廣泛應用於醫學影像、計算機視覺、遙感和攝影等領域,以提高影像質量並獲得更詳細的視覺資訊。
Python Pillow (PIL) 庫在其 ImageEnhance 模組中提供了Contrast() 類,用於對影像應用對比度增強。
增強影像對比度
要調整影像的對比度,您可以將ImageEnhance.Contrast() 類與增強因子一起應用於影像物件。它可以控制影像的對比度,就像調整電視機的對比度一樣。
以下是 ImageEnhance.Contrast() 類的語法:
class PIL.ImageEnhance.Contrast(image)
以下是實現影像對比度增強的步驟:
使用ImageEnhance.Contrast() 類建立一個對比度物件。
然後使用contrast_object.enhance() 方法應用增強因子。
增強因子是一個傳遞給通用單介面方法 enhance(factor) 的浮點值,它在調整影像對比度方面起著重要作用。當使用 0.0 的因子時,它將產生一個純灰色的影像。1.0 的因子將給出原始影像,而當使用更大的值時,影像的對比度會增加,使其在視覺上更清晰。
示例
以下示例演示瞭如何使用 PIL.ImageEnhance 模組實現高對比度影像。
from PIL import Image, ImageEnhance # Open the input image image = Image.open('Images/flowers.jpg') # Create an ImageEnhance object for adjusting contrast enhancer = ImageEnhance.Contrast(image) # Display the original image image.show() # Enhance the contrast by a factor of 2 and display the result enhancer.enhance(2).show()
輸入影像

輸出影像
輸出輸入影像的高對比度版本:

示例
要降低影像的對比度,可以使用小於 1 的對比度增強因子。以下是一個示例,說明了如何使用 PIL.ImageEnhance.Contrast 類建立輸入影像的低對比度版本。
from PIL import Image, ImageEnhance # Open the input image image = Image.open('Images/flowers.jpg') # Create an ImageEnhance object for adjusting contrast enhancer = ImageEnhance.Contrast(image) # Display the original image image.show() # Reduce the contrast by a factor of 0.5 and display the result enhancer.enhance(0.5).show()
輸入影像

輸出影像
輸出輸入影像的低對比度版本:

廣告