JPaul has asked for the wisdom of the Perl Monks concerning the following question:

Greetings all;

I have a client who needs a piece of software to take a random number of TIFFs and put them together into a TIFF Directory (multipage TIFF).
Currently I have proffered a script using ImageMagick/PerlMagick which simply creates a new image object, reads in all the other TIFFs in order, and writes. Thanks to ImageMagicks... well, magic, everything works and I have a perfect TIFF Directory.

Unfortunately the client is processing some 10s of thousands of TIFFs at a time, and ImageMagick through perl simply isn't quick enough - some 8 hours on a 1GHz box. I'd like to tell the client that doing that many freakin' TIFFs is just going to take some time, whether they like it or not - but I have no doubt there is a faster way to do it.
Again, unfortunately, while I'm not so shabby with perl - I generally wrestle with C.
Is anyone famaliar of a faster, perhaps more dedicated, TIFF manipulation library than I could use?
I suspect the solution is to write this in C, but with my skill in the language I'm probably asking for trouble.

My thanks for all your thoughts;

-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

  • Comment on Manhandling image files (TIFFs) quickly

Replies are listed 'Best First'.
Re: Manhandling image files (TIFFs) quickly
by liz (Monsignor) on Sep 08, 2003 at 20:37 UTC
    Are you sure the bottleneck is in Perl? Have you benchmarked or dproffed that? The way I understand it, PerlMagick is but a very thin layer on top of a very optimized ImageMagick. You may be spending most of the CPU's time in optimized C code already, which makes it rather pointless to start doing the remaining Perl bits in C.

    This probably doesn't help you directly, but may put you in a better position when discussing this with your client.


      I'm very certain that there is nothing wrong with perl, not PerlMagick, but simply ImageMagick not being built for the speed that I require.
      ImageMagick is an excellent piece of software and does very, very well what it was designed for - unfortunately I need something faster, which means ImageMagick minus 95% of its code (leaving only the bare TIFF code, of course).

      I meant that ImageMagick would be the object to replace, rather than perl at all, in C.
      How could the problem ever be in perl? It's perfect ;)

      -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: Manhandling image files (TIFFs) quickly
by halley (Prior) on Sep 08, 2003 at 20:34 UTC
    I've done TIFF handling in C as well, and it's always going to take time to process images. The free "libtiff" may be over-engineered for your task however, and you can probably find some shortcuts if your problem is narrowly constrained. The problem with many TIFF libraries is that in order to support all possible TIFFs, there's a lot of overhead in their parsing and encoding which may not apply to you.

    I recommend you do some calculations of the bytesize of the image, versus the bandwidth of harddisk->memory->harddisk. If the software itself isn't killing you by being stupidly redundant, the hardware is going to be your bottleneck.

    [ e d @ h a l l e y . c c ]

Re: Manhandling image files (TIFFs) quickly
by MrCromeDome (Deacon) on Sep 08, 2003 at 20:35 UTC
    I attempted the exact same thing you are trying to accomplish here, and had much similar results. I was greatly dissatisfied with the performance of TIFF compression offered by Image::Magick (it is worth saying that I was greatly satisfied at the ease of working with images however). I ended up being left with one of two choices:
    • If space isn't a consideration, turn off compression and watch Image::Magick scream
    • Rewrite the application with another toolkit and/or another language
    Space was a huge concern for me, so I rewrote the application in C++ using LeadTools. It's an expensive (Windows-only) alternative, but in my case we fortunately had a licensed copy lying around.

    Hope this is more helpful than discouraging. Good luck to you!

      I would be very interested to know what kind of speed benefits you found in moving to your own solution with LeadTools over ImageMagick; Was it profound, or simply "enough" to make it worth the time in development?

      -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

        Leadtools is ridiculously fast, and I was using a version that was about 5 years old or so. I imagine newer releases are faster yet. You pay for the speed though. Last time I checked, their price for the document imaging toolkit was around $2000. If you're going to use this for other projects, I highly recommend it. Or, if your client has deep pockets and is willing to pay, then I'd recommend it too ;)

        Hope this helps. Let me know if there's more I can do.