使用 Pillow 库计算图像中每个波段的所有像素的中值
本程序中,我们将使用 Pillow 库计算每个通道中所有像素的中值。图像中总共有 3 个通道,因此我们将获得一个包含三个值列表。
原始图像

算法
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 median of the pixels.
示例代码
from PIL import Image, ImageStat
im = Image.open('image_test.jpg')
stat = ImageStat.Stat(im)
print(stat.median)输出
[41, 43, 40]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP