Page 1 of 1

memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-18T12:30:46-07:00
by kgc
Limiting memory usage by IM is a popular topic but I haven't been able to find out if what I'm looking for is possible.
After some trial and error the following convert arguments produce fairly good results for the fax, however, the memory used, and time it takes, well, it's fairly ridiculous! (Several gigs for a couple of pages?!)

Code: Select all

convert -normalize  -density 204x196 -resize 1728x2156\! -black-threshold 30 \
  -compress Fax -units PixelsPer Inch $input $output
I've had success limiting memory usage with the -limit directives but the increased processing time due to using temp files in place is substantial.

A colleague mentioned that he thought there were ways to tell IM to sacrifice the quality of certain operations to reduce memory usage and processing time which would be ideal for this application. Is this the case, and if so, any suggestions how?

Thanks.

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-18T12:54:56-07:00
by magick
ImageMagick stores images in RGBA format (consumes 4 channels per pixel) even for black and white images. ImageMagick 7.0.0, which is in development, will only use 1 channel instead of 4 for black and white images. Unfortunately it is not completely implemented just yet. An alternative is to use the Q8 version of ImageMagick (1 byte per pixel component) instead of the Q16 (default build of 2 bytes per pixel component). The Q8 version reduces the memory requirements by 1/2.

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-19T15:13:03-07:00
by kgc
q8 is a compile time option?

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-20T04:15:06-07:00
by glennrp
kgc wrote:q8 is a compile time option?
It's a configure-time option; put

Code: Select all

--with-quantum-depth=8
on your configure command.

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-23T10:42:00-07:00
by kgc
The q8 version is a substantial improvement over the default q16.

Thanks!

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-23T11:15:34-07:00
by kgc
I spoke too soon. The q8 version is substantially faster but, with at least one test pdf, is producing an all black page where the original version of IM was producing a reasonable quality tiff for faxing.

I was originally working with ImageMagick-6.5.4.7-5.el6 (dist. rpm for RHEL/Scientific Linux 6x x86_64), and upgraded to 6.7.3-7. Compile options for 6.7.3-7 based off the dist's rpm.

Code: Select all

./configure --enable-shared --disable-static --with-quantum-depth=8 --with-modules  --with-x --with-threads \
            --with-magick_plus_plus --with-gslib --with-wmf --with-lcms --with-rsvg --with-xml  --without-dps --prefix=/opt/imagemagick-q8-6.7.3-7 
In both cases, the pdf is converted with the following arguments.

Code: Select all

convert -normalize  -density 204x196 -resize 1728x2156\! -black-threshold 30 -compress Fax -units PixelsPerInch in.pdf out.tiff
Original test pdf http://kgc.members.sonic.net/test.pdf
Output from dist's IM rpm http://kgc.members.sonic.net/orig.tiff
Output from q8 compiled from source http://kgc.members.sonic.net/new.tiff

Any suggestions?

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-23T11:29:17-07:00
by fmw42
try the following with formal IM 6 syntax and see if that helps see http://www.imagemagick.org/Usage/basics/#why

convert -density 204x196 -units PixelsPerInch in.pdf -normalize -resize 1728x2156\! -black-threshold 30 -compress Fax out.tiff


Note your problem is likely with -black-threshold 30

In Q16 that is 30 out of 65535. In Q8 it is 30 out of 255. You would be better using percent values than raw values.

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-23T11:53:59-07:00
by kgc
There's no apparent change in the output either by reordering arguments as suggested or eliminating the normalize or black-threshold.

It looks like the new version is getting a transparent png back from gs, where the old version was getting a raw pnm -- the problem appears that the new version is filling the transparent png with black.

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-23T12:54:03-07:00
by fmw42
you may need to edit your delegates.xml to change the device for pdf between pngalpha and pnmraw

the former allow transparency but not multiple pages and the latter allows multiple pages but not transparency


have you tried

convert -density 204x196 -units PixelsPerInch in.pdf -auto-level -resize 1728x2156\! -compress Fax out.tiff

or

convert -density 204x196 -units PixelsPerInch in.pdf -resize 1728x2156\! -monochrome -compress Fax out.tiff

what happens if you remove the -compress Fax

Re: memory and cpu usage in pdf to tiff for fax conversion

Posted: 2011-11-28T11:06:18-07:00
by kgc
Turning off fax compression generates as transparent tiff, the other options had no affect. Turning alpha off appears to produce the desired results but this really seems like a bug, or at least, really not DWIM.

convert -density 204x196 -units PixelsPerInch in.pdf -alpha off -resize 1728x2156\! -compress Fax out4.tiff