Monday, April 07, 2008

ImageMagickで、2値化した画像を半透明グラデーションにする

2値化した画像を半透明グラデーションにするには、以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.9-Q16
%im%\convert.exe tree1.jpg -threshold 50%% -negate -matte -channel rgba -fill #00000000 -transparent #000000ff -channel a -fx "p.r>0?(h-j)/h:0" sample355a.png
rem 重ねあわせ例
%im%\convert.exe -size 300x225 pattern:checkerboard sample355a.png -composite sample355b.jpg

上記バッチでは、以下の処理を実行しています。
1. 画像を50%の閾値で2値化し、反転。
2. 黒色部分を透明にし、アルファチャネルで黒色以外の部分を-fxを使用して縦グラデーションにしています。
3. 市松模様と生成した半透明グラデーションを重ね合わせ。

元画像(tree1.jpg)


出力画像(sample355b.jpg)

No comments: