LoginSignup
19
19

More than 5 years have passed since last update.

ImageMagick > 画像内の特定色のピクセル数をカウントする

Last updated at Posted at 2015-01-27

動作環境

CentOS 6.5
ImageMagickインストール済み

画像ファイルの中のある色のカウントを数えたいとする。

カウントしたい色のRGB値がわかっていればImageMagickに含まれるconvertコマンドを使えばいい。

convert Screenshot.png -fill black +opaque "rgb(128,128,128)" -format %c histogram:info:

上記の実行結果として、以下のような情報が得られる

 900298: (  0,   0,   0) #000000 black
     78: (128, 128, 128) #808080 fractal 

上記のコマンドではRGB値が(128,128,128)のピクセル以外をすべて黒にした上で、黒色と(128,128,128)の色のカウントを数えている。


convert Screenshot.png -format %c histogram:info:

を実行すると、二値化を行わずにあらゆる色のカウント数を得られる。これはこれで使えるかも。

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19