I'm trying to blur the lower part of an image and repeat this for several hundred other images within a target folder. I'm using this command:
magick 1.jpg -write-mask mask.png -blur 0x60 write-mask 2.jpg
This does the the blurring but it takes between 10 - 20 seconds for one 5888 × 2944 image.
Is there someway to speed up this above command or is there a better command which will quickly batch blur a group of images?
Thanks!
CodePudding user response:
In Imagemagick, you can blur a region by blurring the whole image, then blend that with the original using mask. You can speed up a large blur by resizing (scaling) the image down, use a smaller blur and then resizing back up.
Input:
Mask:
Slow:
time magick barns_grand_tetons.jpg \
\( clone -blur 0x60 \) \
barns_grand_tetons_mask.png \
-compose over -composite slow_blur.jpg
4.521s
Fast:
time magick barns_grand_tetons.jpg \
-set option:dims "%wx%h" \
\( clone -scale 10% -blur 0x6 -scale "%[dims]" \) \
barns_grand_tetons_mask.png \
-compose over -composite fast_blur.jpg
0.368s
See
Fast:
time magick barns_grand_tetons.jpg \
-set option:dims "%wx%h" \
\( clone -scale 10% -blur 0x6 -scale "%[dims]" \) \
\( barns_grand_tetons_mask.png -scale 20% -blur 0x2 -level 0x50% -scale "%[dims]" \) \
-compose over -composite fast_blur.jpg
0.404s
If you want to feather outside the mask rather than inside the mask (as above), then change -level 0x50% to -level 50x100%.