Ben Chuanlong Du's Blog

It is never too late to learn.

Calculate Statistics About an Image Using Pillow in Python

In [27]:
import numpy as np
from PIL import Image, ImageOps, ImageStat
In [28]:
img = Image.open("../../home/media/poker/4h.png")
img
Out[28]:
In [22]:
stat = ImageStat.Stat(img)
In [23]:
type(stat)
Out[23]:
PIL.ImageStat.Stat
In [24]:
stat.extrema
Out[24]:
[(13, 255), (0, 255), (0, 255)]
In [25]:
stat.mean
Out[25]:
[213.15465465465465, 183.75525525525526, 189.05905905905905]
In [26]:
stat.count
Out[26]:
[1998, 1998, 1998]
In [14]:
stat.sum
Out[14]:
[425883.0, 367143.0, 377740.0]
In [15]:
stat.sum2
Out[15]:
[95739299.0, 83199915.0, 85284178.0]
In [16]:
stat.median
Out[16]:
[237, 236, 237]
In [17]:
stat.rms
Out[17]:
[218.9008155925123, 204.06273324421366, 206.60293747614958]
In [19]:
stat.stddev
Out[19]:
[49.82630094761174, 88.74460696388873, 83.3153404930748]
In [ ]:
 

Comments