使用 Pillow 庫計算影像中每個波段的所有畫素的中值


本程式中,我們將使用 Pillow 庫計算每個通道中所有畫素的中值。影像中總共有 3 個通道,因此我們將獲得一個包含三個值列表。

原始影像

演算法

Step 1: Import the Image and ImageStat libraries.
Step 2: Open the image.
Step 3: Pass the image to the stat function of the imagestat class.
Step 4: Print the median of the pixels.

示例程式碼

from PIL import Image, ImageStat
im = Image.open('image_test.jpg')
stat = ImageStat.Stat(im)
print(stat.median)

輸出

[41, 43, 40]

更新於: 17-3-2021

769 人檢視

開啟你的 職業生涯

完成課程,獲得認證

開始學習
廣告