Poor performance of convert --annotate on high resolution images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hdoverobinson
Posts: 3
Joined: 2017-09-25T21:56:31-07:00
Authentication code: 1151

Poor performance of convert --annotate on high resolution images

Post by hdoverobinson »

Hello,

I am trying to annotate a stream of very high resolution images that are typically 5000x5000px. I am finding that this operation is using up a lot of system resources and annotating a single image can take a long time. Is this expected behavior for what should be (at least in my mind) a simple operation? I am using convert --annotate.

I have tried with the IM version that is currently distributed by Ubuntu: 6.8.9-9 Q16. I have also tried compiling with Q8 as I read that this can improve performance, but I had similar performance on 7.0.7-3 Q8 as before. I also tried a workaround where I created a transparent PNG with my text on it and then used convert --composite to overlay the annotated PNG onto the large image but this took just as long and just as much system resources as using convert --annotate.

Is there a faster way to annotate the images other than using better hardware?

Thank you
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Poor performance of convert --annotate on high resolution images

Post by fmw42 »

Can you provide an example image and your timings and exact command line?

convert --annotate is not proper syntax. Nor is convert --composite
hdoverobinson
Posts: 3
Joined: 2017-09-25T21:56:31-07:00
Authentication code: 1151

Re: Poor performance of convert --annotate on high resolution images

Post by hdoverobinson »

You know what - now that I am redoing these tests in a clean environment I am finding that the composite workaround DOES improve the speed significantly as expected. Here are the commands I am running with the run times:

Annotation directly on original image:
time convert INPUT.png -quality 100 -font Helvetica -pointsize 32 -fill white -gravity north -annotate +0+75 'TEST TEST TEST TEST TEST' OUTPUT.png
real 1m16.483s
user 1m13.448s
sys 0m1.052s

Transparent PNG with the text:
time convert -size 1000x300 xc:none -font Helvetica -pointsize 32 -fill white -gravity center -annotate +0+0 'TEST TEST TEST TEST TEST' TEXT.png
real 0m0.042s
user 0m0.036s
sys 0m0.008s

And the composite of the original image with the text PNG:
time convert INPUT.png TEXT.png -quality 100 -gravity north -composite OUTPUT.png
real 0m7.002s
user 0m6.744s
sys 0m0.108s

Rather than delete this it may be helpful to others trying to do the same to large images. I am now trying to work out the best way to combine the last two commands into one - to create the PNG with text and then composite it to the original.

Thanks
hdoverobinson
Posts: 3
Joined: 2017-09-25T21:56:31-07:00
Authentication code: 1151

Re: Poor performance of convert --annotate on high resolution images

Post by hdoverobinson »

The inconsistency in previous tests was a result of my EC2 credits running out and CPU being throttled. The performance of convert -annotate directly on the large images was still unacceptable for my application so I am now using this command to create the composite:

convert INPUT.png \( -size 2000x300 xc:none -font Helvetica -pointsize 32 -fill white -gravity SOUTH -annotate +0+75 'TEXT TEXT TEXT TEXT TEXT' +append \) -gravity SOUTH -quality 100 -composite OUTPUT.png

This works well for my application as a workaround to the slow annotation on the high res images.

Thanks
Post Reply