Python-wand: How can I read image properties/statistics -
Python-wand: How can I read image properties/statistics -
i trying extract statistics image such "mean", "standard-deviation" etc. however, cannot find related in python-wand documentation it.
from command line can such statistics this:
convert myimage.jpg -format '%[standard-deviation], %[mean], %[max], %[min]' info:
or
convert myimage.jpg -verbose info:
how such info python programme using wand?
currently, wand doesn't back upwards of statistic methods imagemagick's c-api (outside of histogram , exif). luckily wand.api offered extending functionality.
find method need in magickwand's documentation. use ctypes implement info types/structures (reference header.h
files) class="lang-py prettyprint-override">from wand.api import library import ctypes class channelstatistics(ctypes.structure): _fields_ = [('depth', ctypes.c_size_t), ('minima', ctypes.c_double), ('maxima', ctypes.c_double), ('sum', ctypes.c_double), ('sum_squared', ctypes.c_double), ('sum_cubed', ctypes.c_double), ('sum_fourth_power', ctypes.c_double), ('mean', ctypes.c_double), ('variance', ctypes.c_double), ('standard_deviation', ctypes.c_double), ('kurtosis', ctypes.c_double), ('skewness', ctypes.c_double)] library.magickgetimagechannelstatistics.argtypes = [ctypes.c_void_p] library.magickgetimagechannelstatistics.restype = ctypes.pointer(channelstatistics)
extend wand.image.image
, , utilize newly supported methods. class="lang-py prettyprint-override">from wand.image import image class mystatisticsimage(image): def my_statistics(self): """calculate & homecoming tuple of stddev, mean, max, & min.""" s = library.magickgetimagechannelstatistics(self.wand) # see enum channeltype in magick-type.h compositechannels = 0x002f homecoming (s[compositechannels].standard_deviation, s[compositechannels].mean, s[compositechannels].maxima, s[compositechannels].minima)
python image-processing statistics imagemagick wand
Comments
Post a Comment