Page 1 of 1

Minimising disk usage during scaling?

Posted: 2007-06-05T10:24:09-07:00
by sacha
Using ImageMagick-6.2.8

I have a large (~450MB) compressed TIFF image:

Code: Select all

TIFF Directory at offset 0x8
  Subfile Type: (0 = 0x0)
  Image Width: 4058 Image Length: 56578
  Resolution: 300, 300 pixels/inch
  Bits/Sample: 8
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Date & Time: "2006:05:17 12:16:33"
  Software: "Adobe Photoshop CS2 Macintosh"
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 21
  Planar Configuration: single image plane
  ICC Profile: <present>, 544 bytes
  Photoshop Data: <present>, 11178 bytes
  RichTIFFIPTC Data: <present>, 2 bytes
  Predictor: horizontal differencing 2 (0x2)
Uncompressed, I believe this would occupy 4,058 x 56,578 x 3 = 688,780,572 bytes.

I'm converting this to a scaled-down progressive RGB JPEG image using the following sequence of MagickWand calls:

Code: Select all

w = NewMagickWand()
MagickReadImage(w, srcfile)
MagickSetImageFormat(w, "JPEG")
MagickScaleImage(w, 179, 2500)
MagickSetInterlaceScheme(w, MAGICK_PlaneInterlace)
MagickSetCompressionQuality(w, 85)
MagickSetImageColorspace(w, MAGICK_RGBColorspace)
MagickWriteImage(w, dstfile)
DestroyMagickWand(w)
During the course of this it creates two ~1.8GB temporary files in my MAGICK_TMPDIR.

I'd imagine the 1.8GB is because my ImageMagick is compiled with 24 bits per channel. However I'm not sure why scaling the image creates any intermediate files, let alone two.

Is there a way I can avoid any disk usage whatsoever, scaling directly from the input file to the output file?

Re: Minimising disk usage during scaling?

Posted: 2007-06-05T11:58:12-07:00
by magick
Is there a way I can avoid any disk usage whatsoever, scaling directly from the input file to the output file?
Yes, use some other program. ImageMagick caches pixels to an intermediate pixel cache as described here: http://www.imagemagick.org/script/architecture.php.

Re: Minimising disk usage during scaling?

Posted: 2007-06-06T03:33:25-07:00
by sacha
Thanks for this, it's very useful.

Incidentally apologies if my terse tone comes across as critical, it's not meant that way, I try to keep things dry for clarity. ImageMagick has enabled us to do good stuff without reinventing the wheel.
Yes, use some other program. ImageMagick caches pixels to an intermediate pixel cache as described here: http://www.imagemagick.org/script/architecture.php.
That clarifies things. However it still seems to leave open the possibility of implementing a bespoke, more space-efficient scaling function, e.g. using the method described in the "Streaming Pixels" section.

I'll look into it, using the code for MagickScaleImage() as my starting point.

Re: Minimising disk usage during scaling?

Posted: 2007-06-06T07:28:36-07:00
by magick
Your tone was fine. ImageMagick sometime is not the best choice because we had to make trade-offs to meet our goal of a general purpose image processor. Some image-processing programs, for example, operate in the depth of the image whereas ImageMagick operates in its quantum-depth which is usually 16. So if you want to scale 1-bit images, for example, a program other than ImageMagick may be the best choice.

Forgot to mention the streaming interface which scales by the width of the image rather than the area of the image. Seems like a reasonable solution to your problem.