ในโปรแกรมนี้ เราจะคำนวณค่ามัธยฐานของพิกเซลทั้งหมดในแต่ละช่องโดยใช้ไลบรารี่ 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]