使用多个核批量模糊图像 [英] Batch blur images using multiple cores
问题描述
我正在尝试使用imagemagick模糊数千(> 50,000)图像的底部。图像分辨率为800x600。命令行代码(如下)有效,但需要很长时间。有没有什么方法可以并行运行,并希望使用system()从R内调用?
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)
(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
推荐答案
我认为这个命令与你正在做的事情非常相似,但FAR更快。看看你是否喜欢这种效果:
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
如果可行,您可以像以前一样使用 GNU Parallel :
If that works, you can use GNU Parallel just as before:
parallel 'convert {} \( +clone -crop +0+525 -blur x4 \) -gravity south -composite results/{}' ::: *.jpg
您还可以将该批次放入名为 BlurTitle
的脚本中像这样:
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
然后使其可执行:
chmod +x BlurTitle
和从 R
调用它:
system("./BlurTitle")
或来自终端的:
./BlurTitle
如果你得到参数列表太长 ,你可以通过在 stdin
上发送参数而不是在命令后发表相反的表达方式:
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/{}'
这篇关于使用多个核批量模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!