使用 Pillow 庫計算影像中每個波段所有畫素的標準偏差
在本程式中,我們將使用 Pillow 庫計算每個通道中所有畫素的標準偏差。影像中共有 3 個通道,因此我們將獲得三個值的列表。
原始影像
演算法
Step 1: Import 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 standard deviation of the pixels.
示例程式碼
from PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.stddev)
輸出
[72.25694839223894, 66.24724750077299, 65.50769196475312]
廣告