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


在本程式中,我們將使用 Pillow 庫計算每個通道中所有畫素的均方根 (rms)。影像中總共有三個通道,因此,我們將得到一個包含三個值列表。

原始影像

演算法

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

示例程式碼

from PIL import Image, ImageStat

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

輸出

[104.86876722259062, 96.13661429330132, 91.8480515464677]

更新於: 2021 年 3 月 18 日

681 次瀏覽

開啟您的事業

完成課程以獲得認證

開始
廣告
© . All rights reserved.