我试图提取图像的统计数据,如“平均值”、“标准差”等。然而,我在python文档中找不到任何与它相关的信息。
在命令行中,我可以获得这样的统计数据:
convert MyImage.jpg -format '%[standard-deviation], %[mean], %[max], %[min]' info:或
convert MyImage.jpg -verbose info:如何使用魔杖从python程序中获取这样的信息?
发布于 2014-10-16 17:48:21
目前,魔棒不支持ImageMagick的C( 直方图和EXIF之外)的任何统计方法。幸运的是,为扩展功能提供了wand.api。
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)wand.image.Image,并使用新支持的方法。from wand.image import Image
class MyStatisticsImage(Image):
def my_statistics(self):
"""Calculate & return tuple of stddev, mean, max, & min."""
s = library.MagickGetImageChannelStatistics(self.wand)
# See enum ChannelType in magick-type.h
CompositeChannels = 0x002F
return (s[CompositeChannels].standard_deviation,
s[CompositeChannels].mean,
s[CompositeChannels].maxima,
s[CompositeChannels].minima)发布于 2017-03-01 18:05:40
以下是@emcconville给任何人的一个很好的建议:
https://stackoverflow.com/questions/26404572
复制相似问题