有没有办法在终端打印图像直方图统计?

时间:2014-12-08 14:09:24

标签: linux image image-processing terminal histogram

我想知道从图像直方图获得均值,模式和中值的最简单方法是什么。我对模式 特别感兴趣。为了澄清,我正在寻找类似的东西:

  

histogram-statistics image.jpg

并输出如下:

Mean:128
Median: 120
Mode: 90

1 个答案:

答案 0 :(得分:2)

是的,使用ImageMagick的identify命令:

identify -verbose image1.png 
Image: image1.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 150x150+0+0
  Units: Undefined
  Type: PaletteAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 8-bit
  Channel statistics:
    Pixels: 22500
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 83.8114 (0.328672)
      standard deviation: 103.634 (0.406408)
      kurtosis: -1.14294
      skewness: 0.82261
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 87.1483 (0.341758)
      standard deviation: 84.6068 (0.331791)
      kurtosis: -1.04099
      skewness: 0.547178
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 68.5556 (0.268846)
      standard deviation: 75.6456 (0.29665)
      kurtosis: -0.809854
      skewness: 0.696317
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 160.584 (0.629743)
      standard deviation: 122.279 (0.479526)
      kurtosis: -1.69938
      skewness: 0.537413
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 83.4827 (0.327383)
      standard deviation: 98.1998 (0.385097)
      kurtosis: -1.04514
      skewness: 0.753059
  Alpha: none   #00000000
  Colors: 87
  Histogram:
      8120: (  0,  0,  0,  0) #00000000 none
      6180: ( 27, 71,148,255) #1B4794 srgba(27,71,148,1)
       109: ( 41, 78,140,255) #294E8C srgba(41,78,140,1)
        71: ( 41, 81,140,255) #29518C srgba(41,81,140,1)
 ...
 ...

除非您使用直方图,否则模式不在那里,但如果使用awk' s将图像转换为这样的ASCII数字,则可以使用NetPBM轻松地计算模式PPM格式(see here):

convert image1.png -compress none ppm:- | awk ...