Page 1 of 1

Resize to large destination slows down at 33%

Posted: 2019-05-28T08:41:47-07:00
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

Re: Resize to large destination slows down at 33%

Posted: 2019-05-28T10:39:17-07:00
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.

Re: Resize to large destination slows down at 33%

Posted: 2019-05-28T11:45:00-07:00
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).

Re: Resize to large destination slows down at 33%

Posted: 2019-05-28T12:26:20-07:00
by fmw42

Re: Resize to large destination slows down at 33%

Posted: 2019-05-29T06:39:14-07:00
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?"

Re: Resize to large destination slows down at 33%

Posted: 2019-05-29T07:18:03-07:00
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.

Re: Resize to large destination slows down at 33%

Posted: 2019-05-29T11:05:21-07:00
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.

Re: Resize to large destination slows down at 33%

Posted: 2019-05-30T07:45:13-07:00
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!