使用 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.

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

示例代码

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 次浏览

开启您的事业

完成课程以获得认证

开始
广告