2008.01.23 00:39 "[Tiff] Tiff Digest, Vol 44, Issue 8, Cropping faxes", by Richard Nolde
If I understand him, he wants to copy the top and bottom N rows to a new image and not modify the original image. Tiffcrop has the ability to extract regions or zones as I call them, from the image and write them to another file. If he know the size of the images in advance, he can compute X as a fraction of the page height, I use N here, and use the flags -E top -Z 1:N,N:N input.tif output.tif. This would extract only the top 1/Nth and the bottom 1/Nth of the input file, sandwiching them together without the intervening N -2/Nths of the file. For a single area, eg only top or bottom, he could use -U px -X nnn -Y nnn instead. If he needs exact numbers of pixels, modify tiffcrop to take a list of X and Y sets instead of a single one.
You have to read the whole image as you can't do random seeks in files with G3/4 compressed data. This was Joris' point about the scanline interface being less than optimal as it is broken for compressed data.
I use the logic I developed for tiffcrop to do zonal extraction of bar
codes from selected portions of pages in a high volume document processing system. Tiffcrop is my contribution to libtiff as a way to return something to the community for all that it has allowed me to do with TIFF images. I only support code128 bar codes at the moment but the design allows for adding any other bar codes types if need be. The bar code reader can be used by anyone who wants it but it is unlikely that it would work with Fax images due to the low resolution and poor quality of most fax machines. This may only be a limitation for code128 bar codes which allow for 4 different widths of bars and are thus much more sensitive to the image quality.
Andy Cave wrote:
> Hi Richard,
I don't think that tiffcrop will do what Erez wants - I think you mis-read his request. He doesn't really want to clip the 'input' image, but extract the first X rows from it and append the last X rows from it into a new image that is 2X high.
You can do that with libtiff with a bit of programming - if all his images are 1 bit he can use the lower level APIs to extract each scanline one at a time and using a simple counter write the first X, ignore the next height-2X and write the final X to a new file.
1. How to clip an image with LibTiff (Erez.Har-Tal@Walgreens.com)
>> Tiffcrop was written to handle just this sort of thing. It is in
>> section of recent releases and/or in CVS. Read the the utilities
>>> man page or type tiffcrop --help to see all the options.
Richard Nolde, tiffcrop author
>> Message: 1
>> Date: Mon, 21 Jan 2008 13:38:09 -0600
>> From: Erez.Har-Tal@Walgreens.com
>> Subject: [Tiff] How to clip an image with LibTiff
>> To: email@example.com
>> >> Content-Type: text/plain; charset=US-ASCII
Please excuse me if I am new to libtiff, so any help would be appreciated.
We deal with faxes in standard mode (204X98 dpi) or fine mode
>>> (204X198 dpi)
saved with compression of type G3 1D.
I need to write a utility that clips the first X rows (pixel) from
>>> the top
of the tiff image and last X rows from the bottom of the tiff image. We will save it to a new tiff image with G3 compression in the height
>>> of 2X
pixels. The first X rows will be the top of the new image and the
>>> last X
rows will be the bottom of the image. The operation to clip the image, should not alter the image nor do any thing that would damage the
Is it doable using libtiff on Unix? Any help and direction will be highly appreciated. Doable using other open source libraries?