Page 1 of 1

Annotating images with convert or montage extremely slow.

Posted: 2017-09-04T22:05:46-07:00
by togiles
I have a script that I've been using for several years, but hadn't used in the past year or so, but am trying to re-purpose it again. Basically, the script annotates a bunch of images using either of the following commands (once per image):

Code: Select all

montage -label "label" ${img} -geometry +0+0 -background Green "${img}.annotated.jpg"
or

Code: Select all

convert ${img} -background Green label:"label" +swap -gravity Center -append "${img}.annotated.jpg"
The input images are all JPG images of around 7-20KB each. Either of the above two approaches is taking well over 30 seconds per image, which is simply too slow as the images that I'm annotating are being created at a faster rate than that. I'm certain this used to take < 1 second per image in the past, and am not sure why things are now so slow :'(. Searching online hasn't found a solution that fixes things for me yet, so hoping someone here can help!

I'm running this on my iMac: macOS Sierra v 10.12.6, 4 cores, 16 GB ram.

Code: Select all

convert --version
Version: ImageMagick 6.9.5-8 Q16 x86_64 2016-09-05 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib djvu fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms ltdl lzma openexr png ps tiff webp x xml zlib

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T04:29:54-07:00
by snibgo
The filesize isn't relevant, but how many pixels in each image? What does "convert -list resource" say?

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T09:34:17-07:00
by fmw42
How big in dimensions are your input JPGs? Can you upload one to some free hosting service and put the URL here so we can test with your version of ImageMagick vs the current version?

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T17:23:24-07:00
by togiles
The dimension of the images are 320x240. I've uploaded a sample here:

https://drive.google.com/open?id=0B5eDV ... mZaTXZGV2s

$ convert -list resource
Resource limits:
Width: 214.7MP
Height: 214.7MP
Area: 34.36GP
Memory: 16GiB
Map: 32GiB
Disk: unlimited
File: 192
Thread: 1
Throttle: 0
Time: unlimited

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T18:11:35-07:00
by magick
We're using ImageMagick 6.9.9-11, the latest release. Your command completed in 1/10 of a second. We're clueless why it take so long on your Mac. Add -debug cache to your command line and post the results here. The debugging includes a timestamp which will help us locate the source of the slowdown.

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T18:53:38-07:00
by togiles
$ time convert -debug cache 20170905/GARAGE2_2017090516301705.jpg -background Green label:"label" +swap -gravity Center -append "annotated/out2.jpg"
2017-09-05T19:51:43-06:00 0:00.010 0.000u 6.9.5 Cache convert[98478]: cache.c/DestroyPixelCache/1121/Cache
destroy
2017-09-05T19:51:43-06:00 0:00.010 0.000u 6.9.5 Cache convert[98478]: cache.c/OpenPixelCache/3870/Cache
open 20170905/GARAGE2_2017090516301705.jpg[0] (Heap Memory, 320x240 600KiB)
2017-09-05T19:52:21-06:00 0:38.500 38.230u 6.9.5 Cache convert[98478]: cache.c/OpenPixelCache/3870/Cache
open label[0] (Heap Memory, 27x15 3.16KiB)
2017-09-05T19:52:21-06:00 0:38.500 38.230u 6.9.5 Cache convert[98478]: cache.c/OpenPixelCache/3870/Cache
open label[0] (Heap Memory, 320x255 638KiB)
2017-09-05T19:52:21-06:00 0:38.500 38.230u 6.9.5 Cache convert[98478]: cache.c/DestroyPixelCache/1121/Cache
destroy label[0]
2017-09-05T19:52:21-06:00 0:38.500 38.230u 6.9.5 Cache convert[98478]: cache.c/DestroyPixelCache/1121/Cache
destroy 20170905/GARAGE2_2017090516301705.jpg[0]
2017-09-05T19:52:21-06:00 0:38.530 38.230u 6.9.5 Cache convert[98478]: cache.c/DestroyPixelCache/1121/Cache
destroy label[0]

real 0m38.540s
user 0m37.559s
sys 0m0.686s

Also to note, I see one CPU pegged at 100% for the convert process during the entire time.

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T18:56:27-07:00
by fmw42
I have tested with both IM 6.9.9.11 Q16 and 6.9.5.8 Q16 on my Mac OSX Sierra; 2.8 GHz Dual Core; 8 GB memory, and 500 GB solid state hard disk.

With IM 6.9.9.8 Q16 for 20 runs in a loop I get less than 0.1 sec per image (except for the first one, which was just after I started my computer and had to let ImageMagick and its delegates launch, so it is longer)

Code: Select all

img="GARAGE2_2017090516301705.jpg"
for ((i=0; i<20; i++)); do
time montage -label "label" ${img} -geometry +0+0 -background Green "${img}.annotated.jpg"
done

real	0m7.536s
user	0m2.501s
sys	0m1.169s

real	0m0.074s
user	0m0.228s
sys	0m0.014s

real	0m0.077s
user	0m0.223s
sys	0m0.014s

real	0m0.073s
user	0m0.227s
sys	0m0.014s

real	0m0.080s
user	0m0.184s
sys	0m0.031s

real	0m0.083s
user	0m0.148s
sys	0m0.028s

real	0m0.073s
user	0m0.218s
sys	0m0.016s

real	0m0.078s
user	0m0.225s
sys	0m0.016s

real	0m0.074s
user	0m0.221s
sys	0m0.016s

real	0m0.073s
user	0m0.191s
sys	0m0.026s

real	0m0.074s
user	0m0.196s
sys	0m0.027s

real	0m0.075s
user	0m0.173s
sys	0m0.032s

real	0m0.073s
user	0m0.222s
sys	0m0.017s

real	0m0.072s
user	0m0.219s
sys	0m0.015s

real	0m0.073s
user	0m0.220s
sys	0m0.016s

real	0m0.073s
user	0m0.223s
sys	0m0.016s

real	0m0.074s
user	0m0.223s
sys	0m0.017s

real	0m0.073s
user	0m0.218s
sys	0m0.017s

real	0m0.077s
user	0m0.212s
sys	0m0.023s

real	0m0.077s
user	0m0.159s
sys	0m0.034s
With IM 6.9.5.8 Q16, times were slightly longer but still around 0.1 sec

Code: Select all

img="GARAGE2_2017090516301705.jpg"
for ((i=0; i<20; i++)); do
time im6958 montage -label "label" ${img} -geometry +0+0 -background Green "${img}.annotated.jpg"
done

real	0m0.113s
user	0m0.222s
sys	0m0.029s

real	0m0.109s
user	0m0.150s
sys	0m0.043s

real	0m0.101s
user	0m0.190s
sys	0m0.037s

real	0m0.102s
user	0m0.227s
sys	0m0.025s

real	0m0.095s
user	0m0.226s
sys	0m0.024s

real	0m0.106s
user	0m0.216s
sys	0m0.029s

real	0m0.102s
user	0m0.228s
sys	0m0.026s

real	0m0.098s
user	0m0.227s
sys	0m0.026s

real	0m0.097s
user	0m0.222s
sys	0m0.028s

real	0m0.100s
user	0m0.224s
sys	0m0.025s

real	0m0.097s
user	0m0.212s
sys	0m0.029s

real	0m0.105s
user	0m0.226s
sys	0m0.031s

real	0m0.098s
user	0m0.224s
sys	0m0.026s

real	0m0.102s
user	0m0.221s
sys	0m0.028s

real	0m0.103s
user	0m0.226s
sys	0m0.028s

real	0m0.098s
user	0m0.212s
sys	0m0.031s

real	0m0.102s
user	0m0.230s
sys	0m0.027s

real	0m0.102s
user	0m0.223s
sys	0m0.024s

real	0m0.097s
user	0m0.224s
sys	0m0.026s

real	0m0.094s
user	0m0.224s
sys	0m0.025s
Fredericks-Mac-mini:desktop fred$ 
From what directory are you processing and storing your images? How did you install ImageMagick? From binary or from source? (From IM binary, MacPorts or Homebrew?)

What version of Freetype are you using? Perhaps it is old and needs updating?

Mine is freetype 2.8_0


P.S. Running your other command:

Code: Select all

img="GARAGE2_2017090516301705.jpg"
for ((i=0; i<20; i++)); do
time im6958 convert ${img} -background Green label:"label" +swap -gravity Center -append "${img}.annotated.jpg"
done

real	0m0.091s
user	0m0.077s
sys	0m0.022s

real	0m0.094s
user	0m0.079s
sys	0m0.022s

real	0m0.082s
user	0m0.077s
sys	0m0.020s

real	0m0.084s
user	0m0.077s
sys	0m0.020s

real	0m0.081s
user	0m0.077s
sys	0m0.022s

real	0m0.082s
user	0m0.079s
sys	0m0.021s

real	0m0.083s
user	0m0.071s
sys	0m0.021s

real	0m0.087s
user	0m0.077s
sys	0m0.024s

real	0m0.082s
user	0m0.076s
sys	0m0.021s

real	0m0.080s
user	0m0.076s
sys	0m0.020s

real	0m0.087s
user	0m0.075s
sys	0m0.021s

real	0m0.092s
user	0m0.085s
sys	0m0.023s

real	0m0.086s
user	0m0.068s
sys	0m0.024s

real	0m0.084s
user	0m0.078s
sys	0m0.022s

real	0m0.081s
user	0m0.078s
sys	0m0.021s

real	0m0.083s
user	0m0.075s
sys	0m0.020s

real	0m0.082s
user	0m0.077s
sys	0m0.022s

real	0m0.084s
user	0m0.078s
sys	0m0.022s

real	0m0.081s
user	0m0.067s
sys	0m0.026s

real	0m0.088s
user	0m0.079s
sys	0m0.023s

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T19:00:51-07:00
by togiles
I installed it using MacPorts, but have since upgraded my os ... going through the steps outlined here right now and will report back:

https://trac.macports.org/wiki/Migration

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T19:21:44-07:00
by togiles
That was my issue ... all is well again with the world. Thanks all for your help in this process!

$ time convert 20170905/GARAGE2_2017090516301705.jpg -background Green label:"label" +swap -gravity Center -append "annotated/out2.jpg"

real 0m0.035s
user 0m0.025s
sys 0m0.007s

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-05T21:17:22-07:00
by fmw42
What was the issue? Bad install from MacPorts, bad OS upgrade, or Freetype?

Re: Annotating images with convert or montage extremely slow.

Posted: 2017-09-06T06:42:57-07:00
by togiles
OS Upgrade led to the slow down, as it was working fine before the upgrade.

Solution was to upgrade Macports and reinstall all packages as described in https://trac.macports.org/wiki/Migration

-Todd