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


在本程式中,我們將使用 Pillow 庫來計算每個通道中所有畫素的均值。影像中總共有三個通道,因此,我們將得到一個由三個值組成的列表。

原始影像

演算法

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 mean of the pixels.

示例程式碼

from PIL import Image, ImageStat

im = Image.open('image_test.jpg')
stat = ImageStat.Stat(im)
print(stat.mean)

輸出

[76.00257724463832, 69.6674300254453, 64.38017448200654]

更新於: 2021 年 3 月 17 日

2K+ 個瀏覽量

開始你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.