Computing the basic statistics of an image

We can use the stat module to compute the basic statistics (mean, median, standard deviation of pixel values of different channels, and so on) of an image, as shown in the following:

s = stat.Stat(im)print(s.extrema) # maximum and minimum pixel values for each channel R, G, B# [(4, 255), (0, 255), (0, 253)]print(s.count)# [154020, 154020, 154020]print(s.mean)# [125.41305674587716, 124.43517724970783, 68.38463186599142]print(s.median)# [117, 128, 63]print(s.stddev)# [47.56564506512579, 51.08397900881395, 39.067418896260094]

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.