why is faster to resize horizontally than vertically ?

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
skiiiks
Posts: 2
Joined: 2011-02-25T10:41:53-07:00
Authentication code: 8675308

why is faster to resize horizontally than vertically ?

Post by skiiiks »

$ time /usr/bin/convert -size "720x>" photo1.jpg -thumbnail "720x>" photo2.jpg

real 0m1.248s
user 0m0.472s
sys 0m0.048s

$ time /usr/bin/convert -size "x720>" photo1.jpg -thumbnail "x720>" photo2.jpg

real 0m2.555s
user 0m0.932s
sys 0m0.160s
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: why is faster to resize horizontally than vertically ?

Post by NicolasRobidoux »

Because, to resize horizontally, you only need one scanline (pixel row) to compute a given pixel (if some common technical conditions are satisfied and taken advantage of), and to resize vertically, you need several. In IM, resizing is, by default, scanline based. Consequently, memory is accessed more efficiently when resizing horizontally.
Last edited by NicolasRobidoux on 2011-02-26T14:57:19-07:00, edited 1 time in total.
skiiiks
Posts: 2
Joined: 2011-02-25T10:41:53-07:00
Authentication code: 8675308

Re: why is faster to resize horizontally than vertically ?

Post by skiiiks »

is there a faster way to do a simple resize ?

i need the image to be as much 720 in X or Y keeping aspect ratio ... that's because I use one or other command depending width > height or viceversa
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: why is faster to resize horizontally than vertically ?

Post by fmw42 »

-scale and -sample are generally faster than -resize, but they do not do antialiasing with any filters. If downsampling, then -scale with average blocks of pixels and -sample will use nearest neighbor subsampling. Thus the quality won't be as good.

Only other way to speed things up is with multiprocessors and OpenMP enabled in IM, as far as I know.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: why is faster to resize horizontally than vertically ?

Post by NicolasRobidoux »

Do I understand correctly that you are resizing in only one direction?

In that case, you may get a speed gain without much quality loss by changing away from the standard filter (which may be Mitchell or Lanczos depending on the type of input image). I suggest

Code: Select all

-filter Hermite
Even if you are resizing in both directions (at least some of the time), you should check whether the results obtained with filters with small support are satisfactory.

In increasing order of complexity, the "cheapest" ones are Triangle, Hermite and Quadratic. (It turns out that all three work well with transparency, and are "halo free." Triangle shows a lot of "ridging," Hermite shows a lot of "jaggies," and Quadratic is quite blurry.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: why is faster to resize horizontally than vertically ?

Post by NicolasRobidoux »

You may also speed up IM by compiling with the Quantum equal to exactly the desired bit-depth of your input and output images.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: why is faster to resize horizontally than vertically ?

Post by anthony »

You could also type using -distort resizing BUT setting -filter point -interpolate bilinear
That turns of the distorts use of a filter (EWA) and instead uses interpolated pixel lookup

I can not guarantee it will be faster, but it might be.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply