Page 1 of 1
Speed Up Resize Operation?
Posted: 2016-08-10T10:00:28-07:00
by ecomp2016
Hi All,
Like my previous thread dealing with caption, is there a way for ImageMagick to resize an image more quickly and efficiently? Of all the measurements I've taken, the resize operation takes about 400MS which is longer than everything else being done in my app using ImageMagick.
I need to optimize for speed and efficiency.
Re: Speed Up Resize Operation?
Posted: 2016-08-10T10:07:24-07:00
by Bonzo
What code are you currently using, platform and language?
Re: Speed Up Resize Operation?
Posted: 2016-08-10T10:09:46-07:00
by fmw42
Try -scale rather than -resize. Or add -filter point before -resize. Or use -thumbnail. If you have lots of meta data or profiles, the -thumbnail will remove them. You could also add -strip after reading your input and before -resize.
Re: Speed Up Resize Operation?
Posted: 2016-08-10T10:37:09-07:00
by ecomp2016
Scale appears to be several times faster and appears to produce similar results. Thanks fmw42.
Re: Speed Up Resize Operation?
Posted: 2016-08-10T10:43:13-07:00
by snibgo
"-sample" is even quicker, but may not give you acceptable results.
Re: Speed Up Resize Operation?
Posted: 2016-08-10T10:55:41-07:00
by ecomp2016
Yeah, sample wasn't respecting the image aspect ratio? I am resizing 400 x 400 in my example, but the picture is not square. When I use resize or scale, the image is resized to a height of 400 and a width of 283 which is correct for its aspect. Sample does 400 x 400 without preserving the aspect?
Re: Speed Up Resize Operation?
Posted: 2016-08-10T11:20:52-07:00
by snibgo
"-sample" should give the same size output as "-resize" or "-scale", given the same input image and geometry argument.
What version IM are you using?
Re: Speed Up Resize Operation?
Posted: 2016-08-11T07:54:13-07:00
by ecomp2016
You're right. It looks like a bug in the Magick.NET wrapper. When I run ImageMagick from the commandline sample does maintain the aspect ratio. I wonder how Magick.NET could even be overwriting this default sample behavior?
Sample doesn't produce great results, but man is it fast! It takes 6 milliseconds to sample resize. Scale takes 200MS, and Resize takes 500+ depending on the image. Is there anything between scale and sample? 200MS is still kind of a long time for this operation.
Re: Speed Up Resize Operation?
Posted: 2016-08-11T16:12:11-07:00
by fmw42
Is there anything between scale and sample? 200MS is still kind of a long time for this operation.
Not that I know. You could try -filter point -thumbnail, but I suspect it will be longer than -scale.
What percent size reduction are you making?
Re: Speed Up Resize Operation?
Posted: 2016-08-11T17:11:27-07:00
by snibgo
Sorry, I don't use MagickNET. I use SampleImage() at the MagickCore level, which works fine.
Sampling is very fast because it doesn't calculate new colours for output pixels. It simply picks the colour of an input pixel. For some purposes, eg zooming in to an image to get "big pixels", or flat-colour graphics, it's the right tool.
I'm not aware of anything between scale and sample. There may be another way to increase performance, eg we sometimes resize then crop when it's faster to crop first and then resize.