
- 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 - 浮雕影像
一般來說,浮雕用於在紙張或卡片上建立凸起的浮雕影像以達到三維效果,在 19 世紀,英國郵政服務就曾廣泛使用這種工藝為郵票增添優雅氣息。此過程涉及凸起影像、設計或文字的某些部分,以建立三維效果。
在影像處理和計算機圖形學中,影像浮雕是一種技術,其中影像中的每個畫素都會根據原始影像的明暗邊界轉換為高光或陰影版本。對比度低的區域將替換為灰色背景。生成的浮雕影像有效地表示原始影像中每個位置的顏色變化率。將浮雕濾鏡應用於影像通常會產生類似於紙張或金屬浮雕的原始影像的輸出,因此得名。
Python 的 Pillow 庫在 ImageFilter 模組中提供了幾個標準影像濾鏡,可以透過呼叫 image.filter() 方法對影像執行不同的濾鏡操作。在本教程中,我們將瞭解 ImageFilter 模組提供的浮雕濾鏡的工作原理。
使用 Image.filter() 方法應用 ImageFilter.EMBOSS 核心濾鏡
ImageFilter.EMBOSS 濾鏡是 Pillow 庫當前版本中提供的內建濾鏡選項之一,用於在影像中建立浮雕效果。
以下是應用影像浮雕的步驟:
使用 Image.open() 函式載入輸入影像。
將 filter() 函式應用於載入的 Image 物件,並將 ImageFilter.EMBOSS 作為函式的引數提供。該函式將返回浮雕影像作為 PIL.Image.Image 物件。
示例
這是一個使用 Image.filter() 方法和 ImageFilter.EMBOSS 核心濾鏡的示例。
from PIL import Image, ImageFilter # Load an input image input_image = Image.open("Images/TP logo.jpg") # Apply an emboss effect to the image embossed_result = input_image.filter(ImageFilter.EMBOSS) # Display the input image input_image.show() # Display the modified image with the emboss effect embossed_result.show()
輸入影像

輸出影像
帶有浮雕效果的輸出濾鏡影像:

自定義 EMBOSS 濾鏡以向浮雕影像新增深度和方位角
在 Pillow 庫的原始碼中,我們可以在“ImageFilter.py”模組中觀察到 EMBOSS 類。此類表示浮雕濾鏡,並提供了一種建立影像浮雕效果的基本方法。
# Embossing filter. class EMBOSS(BuiltinFilter): name = "Emboss" # fmt: off filterargs = (3, 3), 1, 128, ( -1, 0, 0, 0, 1, 0, 0, 0, 0, )
該濾鏡透過逐畫素將矩陣應用於影像來操作。矩陣包含確定應用於每個畫素的變換的值。透過修改矩陣,您可以控制浮雕效果的方位角和強度。
矩陣是一個 3x3 網格,其中每個元素對應於當前畫素及其周圍畫素。中心值表示正在處理的當前畫素。該濾鏡根據矩陣中它們的權重組合這些值以建立變換後的畫素。您可以透過調整縮放和偏移引數來自定義濾鏡,這些引數會影響效果的整體強度。
示例
以下是一個演示如何將自定義浮雕濾鏡應用於影像的示例,允許您透過調整各種引數來控制浮雕效果的外觀。
from PIL import Image, ImageFilter # Open the input image image = Image.open('Images/TP logo.jpg') # modify the filterargs such as scale, offset and the matrix ImageFilter.EMBOSS.filterargs=((3, 3), 2, 150, (0, 0, 0, 0, 1, 0, -2, 0, 0)) # Apply an emboss effect to the image embossed_result = image.filter(ImageFilter.EMBOSS) # Display the input image image.show() # Display the modified image with the emboss effect embossed_result.show()
輸入影像

輸出影像
帶有自定義浮雕效果的輸出濾鏡影像:
