Resize to large destination slows down at 33%

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
String
Posts: 4
Joined: 2019-05-28T08:34:34-07:00
Authentication code: 1152

Resize to large destination slows down at 33%

Post by String »

I'm processing some astronomical images of reasonable size, and in my experience, the -resize operation (or equivalents) slows down greatly when it hits 33%. Running from the command line with the -monitor option, up until that point it's just whizzing along - then it all but stops, dropping to ~1 second per scanline (which equates to many hours per image). Here's a typical command:

Code: Select all

D:\temp> magick -version
Version: ImageMagick 7.0.8-46 Q8 x64 2019-05-19 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP(2.0)
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib

D:\temp> magick mogrify -monitor -format mpc -resize 65536x32768! Lunar_26k.jpg
load image[Lunar_26k.jpg]: 12999 of 13000, 100% complete
resize image[Lunar_26k.mpc]: 32750 of 98304, 33% complete
The larger the destination, the more pronounced the effect, but it still happens with sizes much smaller than this. Always happens right at 33%, though, regardless of file size - which tells me that it's not hitting a physical limitation (like RAM). And watching my system performance monitor, it doesn't seem to be bound by CPU, RAM, or disk access.

It's happening with convert, mogrify, and other variants I've tried that do resizing.

Any thoughts? Am I running into a ceiling somewhere that I can tweak with a setting? Does this look like a bug? Some other explanation?

FWIW, the image from the command above is available at https://lunescope.app/app_server/map/Lunar_26k.jpg
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Resize to large destination slows down at 33%

Post by magick »

Use -scale rather than -resize. Resizing is a two pass process that causes ImageMagick to read pixels in a non-optimal manner, column-wise rather than row-wise. That's fine for memory, but as you found, very slow on disk.
String
Posts: 4
Joined: 2019-05-28T08:34:34-07:00
Authentication code: 1152

Re: Resize to large destination slows down at 33%

Post by String »

That solves it - thanks!

Might I suggest that -scale is mentioned in the -resize documentation as an alternative? I simply hadn't found it, or I probably would have tried it (and not cluttered the forum with this post).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize to large destination slows down at 33%

Post by fmw42 »

String
Posts: 4
Joined: 2019-05-28T08:34:34-07:00
Authentication code: 1152

Re: Resize to large destination slows down at 33%

Post by String »

Thanks, Fred. I greatly respect all the effort you've put into IM - but "all the rest of the pages at http://www.imagemagick.org/Usage/" is one shedload of material to learn before using the software.

And I'm really more of a reference than tutorials kind of guy - that's just my learning style. Which is why I was suggesting that perhaps the reference doc at https://www.imagemagick.org/script/comm ... hp?#resize could have a note like the first reply to my OP: for many uses, -scale is a better-optimized choice than -resize.

It'd save folks like me many hours of wasted time: "Hey, I need to resize some images. Here's a -resize option, that looks like the thing to use. Yep, reading the docs, that looks right. Seems to work, my images are coming out the right size. Hmmm, why is it so slow?"
Last edited by String on 2019-05-29T07:51:24-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize to large destination slows down at 33%

Post by snibgo »

@String: I sympathise. I also prefer reference to tutorials.

But I don't see a simple solution. For example, there are five basic operations for resizing: "-resize", "-scale", "-sample", "-distort SRT" and "-distort Resize". Oh, and "-thumbnail" and "-resample" and some others. Perhaps the reference documentation for each of these could all refer to the others, and list the advantages of each.

Personally, I think the reference page http://www.imagemagick.org/script/comma ... php#resize should link to the tutorial at http://www.imagemagick.org/Usage/resize/ .

But that reference page doesn't link to the "usage" pages. It is up to the reader to (a) realise that there are tutorial-style usage pages and (b) to find them.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize to large destination slows down at 33%

Post by fmw42 »

Unfortunately, the author of the Usage/Reference pages is unable to contribute further to ImageMagick and no one has volunteered to improve the ImageMagick documentation. The IM developers are primarily two people and they have other commitments and little time other than to fix bugs. So one will have to do with this documentation until someone else contributes better ones.
String
Posts: 4
Joined: 2019-05-28T08:34:34-07:00
Authentication code: 1152

Re: Resize to large destination slows down at 33%

Post by String »

Ah, the curse of open source. OK, fair enough - I certainly have neither the time nor the expertise to take this on, so it's not reasonable for me to expect anyone else to shoulder the burden.

Thanks for all you've done!
Post Reply