ในโปรแกรมนี้ เราจะคำนวณค่าเฉลี่ยของพิกเซลทั้งหมดในแต่ละช่องสัญญาณโดยใช้ไลบรารี่ของ 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 mean of the pixels.
โค้ดตัวอย่าง
from PIL import Image, ImageStat
im = Image.open('image_test.jpg')
stat = ImageStat.Stat(im)
print(stat.mean) ผลลัพธ์
[76.00257724463832, 69.6674300254453, 64.38017448200654]