Saturday, May 19, 2007

ImageMagickで透過PNGのエッジ抽出画像を生成する

ImageMagickで透過PNGのエッジ抽出画像を生成するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.4-Q16
%im%\convert.exe sample9b.jpg -enhance -enhance -enhance -enhance -enhance -edge 2 -threshold 50%% -channel A -fx "p.r==1?1:0" -channel RGB -fx "p==1?#2050C0:0" -channel RGBA -blur 1 sample160.png
%im%\convert.exe sample9b.jpg -fx "(r+g+b)/3" sample160.png -composite sample160b.png

元画像(sample9b.jpg)


出力画像(sample160.png)


白黒画像と重ねあわせた例(sample160b.png)

ImageMagickでだんだんと白黒画像になっていくグラデーションを作成する

ImageMagickでだんだんと白黒画像になっていくグラデーションを作成するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.4-Q16
%im%\convert.exe sample10.jpg -channel A -fx "1-sqrt(pow(150-i,2)+pow(50-j,2))/100" t1.png
%im%\convert.exe sample10.jpg -fx "(r+g+b)/3" t1.png -composite sample159.jpg

上記のバッチでは、座標(150,50)から遠ざかるほどに白黒画像になります。

元画像(sample10.jpg)


出力画像(sample159.jpg)

ImageMagickで一部分だけ焦点のあっている画像に処理する

ImageMagickで一部分だけ焦点のあっている画像に処理するには、
以下のバッチファイルを実行します。

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.4-Q16
%im%\convert.exe -size 200x100 xc:none -fill white -draw "ellipse 50,50 40,40 0,360" sample8.jpg -compose srcin -composite p1.png
%im%\convert.exe -size 200x100 xc:none -fill white -draw "ellipse 50,50 45,45 0,360" sample8.jpg -compose srcin -composite -channel RGBA -blur 0x1 p2.png
%im%\convert.exe -size 200x100 xc:none -fill white -draw "ellipse 50,50 55,55 0,360" sample8.jpg -compose srcin -composite -channel RGBA -blur 0x2 p3.png
%im%\convert.exe -size 200x100 xc:none -fill white -draw "ellipse 50,50 70,70 0,360" sample8.jpg -compose srcin -composite -channel RGBA -blur 0x3 p4.png
%im%\convert.exe sample8.jpg -blur 0x4 p4.png p3.png p2.png p1.png -flatten sample158.png

上記のバッチでは、座標(50,50)を中心とした同心円をそれぞれ切り抜き、ぼかしを外側に向かって
強くかけるようにしています。

元画像(sample8.jpg)


出力画像(sample158.png)

ImageMagickで画像の上下を半透明グラデーションにする

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

rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.4-Q16
%im%\convert.exe sample3b.jpg -channel A -fx "abs(sin(pi*j/h))" sample157a.png
%im%\convert.exe -size 150x150 pattern:checkerboard -gravity center sample157a.png -composite sample157b.jpg

元画像(sample3b.jpg)


出力画像(sample157a.png)


重ねあわせ例(sample157b.jpg)


2008/01/04追記
ver6.3.7では、以下のバッチファイルのように-channelの前に-matteを追加します。
rem 環境によって変えてね
set im=C:\Progra~1\ImageMagick-6.3.7-Q16
%im%\convert.exe sample3b.jpg -matte -channel A -fx "abs(sin(pi*j/h))" sample157a.png
%im%\convert.exe -size 150x150 pattern:checkerboard -gravity center sample157a.png -composite sample157b.jpg

関連項目
ImageMagickで上下・左右に半透明グラデーションをかける