使用 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 variance of the pixels.
示例程式碼
from PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.var)
輸出
[5221.066590958682, 4388.697801428673, 4291.257706548981]
廣告