Batch blur images using multiple cores

我怕爱的太早我们不能终老 提交于 2019-12-12 04:26:08

问题


I'm trying to blur the bottom section of thousands (>50,000) of images using imagemagick. Image resolution is 800x600. The command line code (below) works, but takes a long time. Is there any way that this can be run in parallel, and hopefully called from within R using system()?

I got this code off the internet, so I'm not sure if it's the best way to even achieve this objective? Any help would be greatly appreciated. Thanks in advance!

(OS = OSX El Capitan)

cd /Users/Desktop/test_images
list=$(ls *.jpg)
for img in $list; do
    convert $img \
    \( -size 800x525 xc:black -size 800x75 xc:white -append \) \
    -compose blur -define compose:args=6 -composite \
    cd /Users/Desktop/test_images/results/$img
done
cd

回答1:


I think this command does something very similar to what you are doing but is FAR quicker. See if you like the effect:

convert start.jpg \( +clone -crop +0+525 -blur x4 \) -gravity south -composite result.jpg

If that works, you can use GNU Parallel just as before:

parallel 'convert {} \( +clone -crop +0+525 -blur x4 \) -gravity south -composite results/{}' ::: *.jpg

You can also put that lot in a script called BlurTitle like this:

#!/bin/bash
parallel 'convert {} \( +clone -crop +0+525 -blur x4 \) -gravity south -composite results/{}' ::: *.jpg

and then make it executable with:

chmod +x BlurTitle

and call it from R with:

system("./BlurTitle")

or from the Terminal with:

./BlurTitle

If you get "Argument list too long", you can express it the other way around like this by sending the arguments on stdin rather than after the command:

cd /path/to/images
find . -name \*.jpg -print0 | parallel -0 'convert {} \( +clone -crop +0+525 -blur x4 \) -gravity south -composite results/{}'


来源:https://stackoverflow.com/questions/40044958/batch-blur-images-using-multiple-cores

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!