Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Calculate Statistics About an Image Using Pillow in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import numpy as np
from PIL import Image, ImageOps, ImageStat
img = Image.open("../../home/media/poker/4h.png")
img
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=37x54 at 0x7F3DD94F6358>
stat = ImageStat.Stat(img)
type(stat)
PIL.ImageStat.Stat
stat.extrema
[(13, 255), (0, 255), (0, 255)]
stat.mean
[213.15465465465465, 183.75525525525526, 189.05905905905905]
stat.count
[1998, 1998, 1998]
stat.sum
[425883.0, 367143.0, 377740.0]
stat.sum2
[95739299.0, 83199915.0, 85284178.0]
stat.median
[237, 236, 237]
stat.rms
[218.9008155925123, 204.06273324421366, 206.60293747614958]
stat.stddev
[49.82630094761174, 88.74460696388873, 83.3153404930748]