
- 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) 庫在其 ImageFilter 模組中提供了一個名為 UnsharpMask() 的類,用於將銳化蒙版濾鏡應用於影像。
銳化蒙版濾鏡
ImageFilter.UnsharpMask() 類表示銳化蒙版濾鏡,用於增強影像銳度。
以下是 ImageFilter.UnsharpMask() 類的語法:
class PIL.ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3)
其中,
radius - 該引數控制模糊半徑。半徑影響要增強的邊緣的大小。較小的半徑會銳化較小的細節,而較大的半徑會在物體周圍產生光暈。調整半徑和強度會相互影響;減小一個允許另一個產生更大的影響。
percent - 它以百分比的形式確定銳化蒙版的強度。百分比控制銳化效果的強度或幅度。它決定在物體邊緣新增多少對比度。較高的強度會導致更明顯的銳化效果,使邊緣邊界更暗和更亮。它不會影響邊緣邊框的寬度。
threshold - 閾值控制需要銳化的亮度變化的最小值。它決定了相鄰色調值需要有多大的差異才能使濾鏡生效。較高的閾值可以防止平滑區域出現斑點。較低的值會銳化更多,而較高的值會保留對比度較低的區域。
示例
以下示例使用 ImageFilter.UnsharpMask() 類和 Image.filter() 方法(使用預設值)將銳化蒙版濾鏡應用於影像。
from PIL import Image, ImageFilter # Open the image original_image = Image.open('Images/Flower1.jpg') # Apply the Unsharp Mask filter with default parameter values sharpened_image = original_image.filter(ImageFilter.UnsharpMask()) # Display the original image original_image.show() # Display the sharpened image sharpened_image.show()
輸出
輸入影像:

使用預設引數值應用銳化蒙版濾鏡後的輸出影像:

示例
這是另一個示例,它使用不同的引數值將銳化蒙版濾鏡應用於影像。
from PIL import Image, ImageFilter # Open the image using Pillow original_image = Image.open('Images/Flower1.jpg') # Apply the Unsharp Mask filter with custom parameters sharpened_image = original_image.filter(ImageFilter.UnsharpMask(radius=4, percent=200, threshold=3)) # Display the original image original_image.show() # Display the sharpened image sharpened_image.show()
輸出
輸入影像:

使用自定義引數值應用銳化蒙版濾鏡後的輸出影像:

廣告