Handling large TIFFs with ImageMagick in Java

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
BenjaminSDS
Posts: 1
Joined: 2011-09-28T15:50:23-07:00
Authentication code: 8675308

Handling large TIFFs with ImageMagick in Java

Post by BenjaminSDS »

I'm a Java developer working in a Linux environment trying to process TIFF files. We receive TIFF images of faxed documents ( usually using eFax or some other fax site that will convert the claims to PDFs ) and need to break it down into single page images. Some of the TIFFs that come through are over 200 pages in length and up to almost 10 MB in size.

The TIFFs will come through distorted a lot of the time so I try to use ImageMagick to clean up the images. The quality isn't very important as the images are typically of faxed letters or receipts, but without running them through re-sample the images get extremely distorted when breaking a multipage claim up into single page tiffs. I've found ImageMagick does a TERRIFIC job re-sampling the images and making them very readable when I resample the image BEFORE splitting it up. However, when dealing with a large TIFF a lot of times the program will run out of memory while processing. I've read that Q8 requires much less memory than the Q16 version. I'm currently running Q16 and I was wondering if there was an 'app-get' command I could use to specify the Q8 version of imagemagick when installing rather than the Q16 version.

I was also wondering if there were some other parameters I could add to help with managing the memory while resampling the image. I use im4java to interface with ImageMagick in my java classes. I'm extremely sorry if this turns out not to be the place to ask, but I use the following code to resample images:

ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
op.addImage( <Source File Path> );
op.resample(200);
op.monochrome();
op.addImage( <Destination File Path> );
cmd.run(op);

I would be extremely grateful for any and all advice on the best way to handle these large images. I tried to break up the TIFF into single page TIFFS ( using the JAI Package ) before re-sampling but breaking up the TIFFs must change some of the properties because the re-sampling usually results in badly stretched images if I break them up first.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Handling large TIFFs with ImageMagick in Java

Post by fmw42 »

If you are installing from source, then you can use --with-quantum-depth=8 in your ./configure. see http://www.imagemagick.org/script/advan ... lation.php

Also see large image processing at http://www.imagemagick.org/Usage/files/#massive

I am not an expert on this, so this is all I can suggest.
Post Reply