2012-05-31 9 views
9

目的は、画像の上にキャプションを置き、テキストの色を、その上に置かれている背景と対比させるものに設定することです。そのために、私は以下の画像の赤い四角形の内側の領域の平均色を計算したい:画像内の領域の平均色を計算する

enter image description here

enter image description here

答えて

5

私はあなたがそれをサイズ変更することに興味があるエリアにトリミングします〜1ピクセル。次に、そのピクセルの値を取得します。

13

拡大表示Bonzo’s answer。これは、例えばコマンドである

convert Y82IirS.jpg -resize 1x1 txt: 

結果ここ

# ImageMagick pixel enumeration: 1,1,255,srgb 
0,0: (220,176, 44) #DCB02C srgb(220,176,44) 

Average colour of an image

0

がトリミングと色検出の両方を処理するコマンドであり、また一貫R、G、Bフォーマットで出力を生成します:

convert image.gif -crop 6x7+8+9 -resize 1x1\! -format "%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]" info:- 

ここで、6x7+8+9

6: image width (pixels) 
7: image height (pixels) 
8: x-coordinate of top left corner 
9: y-coordinate of top left corner 

戻りhttps://stackoverflow.com/a/25488429/3124680

から適応

176,191,67