0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ImageMagick 指定領域のRGB値を列挙する

Posted at

背景

画像を解析にて、ある領域のRGB値を抽出して列挙したいときに活用します。

環境

Windows 7 SP1(32bit)
ImageMagick 7.0.3-2 Q8 x86
にて確認しました。

コード

RGB値抽出の内容については、以前投稿した記事を参照ください。

extractColors.bat
@echo off
if "%1" == "" goto HELP

echo X, Y = R, G, B
for /L %%Y in (%3, 1, %5) do (
for /L %%X in (%2, 1, %4) do (
magick convert %1 -crop 1x1+%%X+%%Y -format "%%X, %%Y = %%[fx:r*255], %%[fx:g*255], %%[fx:b*255]\n" info:
)
)

goto END

:HELP
echo 入力画像の指定領域のRGB値を表示します。
echo.
echo 書式
echo extractColors.bat [FileName] [X_Start] [Y_Start] [X_End] [Y_End]
echo.
echo [FileName] 入力ファイル名
echo [X_Start]  抽出開始(左上) X座標
echo [Y_Start]  抽出開始(左上) Y座標
echo [X_End]    抽出終了(右下) X座標
echo [Y_End]    抽出終了(右下) Y座標
:END

実施例

sample.png
↑幅4x高さ2画素の画像です

c:\work>extractColors.bat sample.png 0 0 3 1
X, Y = R, G, B
0, 0 = 255, 0, 0
1, 0 = 195, 0, 255
2, 0 = 0, 107, 255
3, 0 = 0, 255, 92
0, 1 = 255, 0, 180
1, 1 = 31, 0, 255
2, 1 = 0, 255, 247
3, 1 = 33, 255, 0
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?