TIFFCROP(1) | LibTIFF | TIFFCROP(1) |
tiffcrop - select, copy, crop, convert, extract, and/or process one or more TIFF files
tiffcrop [ options ] src1.tif … srcN.tif dst.tif
tiffcrop processes one or more files created according to the Tag Image File Format, Revision 6.0, specification into one or more TIFF file(s). tiffcrop is most often used to extract portions of an image for processing with bar code recognizer or OCR software when that software cannot restrict the region of interest to a specific portion of the image or to improve efficiency when the regions of interest must be rotated. It can also be used to subdivide all or part of a processed image into smaller sections and export individual images or sections of images as separate files or separate images within one or more files derived from the original input image or images.
The available functions can be grouped broadly into three classes:
Functions are applied to the input image(s) in the following order: cropping, fixed area extraction, zone and region extraction, inversion, mirroring, rotation.
Functions are applied to the output image(s) in the following order: export mode options for grouping zones, regions, or images into one or more files, or row and column divisions with output margins, or page size divisions with page orientation options.
Finally, strip, tile, byte order, output resolution, and compression options are applied to all output images.
The output file(s) may be organized and compressed using a different algorithm from the input files. By default, tiffcrop will copy all the understood tags in a TIFF directory of an input file to the associated directory in the output file. Options can be used to force the resultant image to be written as strips or tiles of data, respectively.
tiffcrop can be used to reorganize the storage characteristics of data in a file, and to reorganize, extract, rotate, and otherwise process the image data as specified at the same time whereas tiffcp does not alter the image data within the file.
Using the options for selecting individual input images and the options for exporting images and/or segments defined as zones or regions of each input image, tiffcrop can perform the functions of tiffcp and tiffsplit in a single pass while applying multiple operations to individual selections or images.
Export mode | Description |
combined | All images and selections are written to a single file with multiple selections from one image combined into a single image (default) |
divided | All images and selections are written to a single file with each selection from one image written to a new image |
image | Each input image is written to a new file (numeric filename sequence) with multiple selections from the image combined into one image |
multiple | Each input image is written to a new file (numeric filename sequence) with each selection from the image written to a new image |
separate | Individual selections from each image are written to separate files |
Each colon delimited series of four values represents the horizontal and vertical offsets from the top and left edges of the image, regardless of the edge specified with the -E option. The first and third values represent the horizontal offsets of the corner points from the left edge while the second and fourth values represent the vertical offsets from the top edge.
The CCITT Group 3 and Group 4 compression algorithms can only be used with bilevel data.
Group 3 compression can be specified together with several T.4-specific options: 1d for 1-dimensional encoding, 2d for 2-dimensional encoding, fill to force each encoded scanline to be zero-filled so that the terminating EOL code lies on a byte boundary. Group 3-specific options are specified by appending a :-separated list to the g3 option; e.g. -c g3:2d:fill to get 2D-encoded data with byte-aligned EOL codes.
LZW compression can be specified together with a predictor value. A predictor value of 2 causes each scanline of the output image to undergo horizontal differencing before it is encoded; a value of 1 forces each scanline to be encoded without differencing. LZW-specific options are specified by appending a :-separated list to the lzw option; e.g. -c lzw:2 for LZW compression with horizontal differencing.
Display program progress and/or dump raw data to non-TIFF files. Options include the following and must be joined as a comma separated list. The use of this option is generally limited to program debugging and development of future options. An equal sign may be substituted for the colon in option:value pairs.
debug:N:
format:txt|raw:
level:N:
input:full-path-to-directory/input-dumpname:
output:full-path-to-directory/output-dumpname:
The four debug/dump options are independent, though it makes little sense to specify a dump file without specifying a detail level.
Note: tiffcrop may be compiled with -DDEVELMODE to enable additional very low level debug reporting.
However, not all option combinations are permitted.
Note 2: Any of the -X, -Y, -Z and -z options together with other PAGE_MODE_x options such as -H, -V, -P, -J or -K are not supported and may cause buffer overflows.
The following concatenates two files and writes the result using LZW encoding:
tiffcrop -c lzw a.tif b.tif result.tif
To convert a G3 1d-encoded TIFF to a single strip of G4-encoded data the following might be used:
tiffcrop -c g4 -r 10000 g3.tif g4.tif
(1000 is just a number that is larger than the number of rows in the source file.)
To extract a selected set of images from a multi-image TIFF file use the -N option described above. Thus, to copy the 1st and 3rd images of image file album.tif to result.tif:
tiffcrop -N 1,3 album.tif result.tif
Invert a bilevel image scan of a microfilmed document and crop off margins of 0.25 inches on the left and right, 0.5 inch on the top, and 0.75 inch on the bottom. From the remaining portion of the image, select the second and third quarters, ie, one half of the area left from the center to each margin:
tiffcrop -U in -m 0.5,0.25,0.75,0.25 -E left -Z 2:4,3:4 -I both MicrofilmNegative.tif MicrofilmPostiveCenter.tif
Extract only the final image of a large Architectural E sized multipage TIFF file and rotate it 90 degrees clockwise while reformatting the output to fit on tabloid sized sheets with one quarter of an inch on each side:
tiffcrop -N last -R 90 -O auto -P tabloid -U in -J 0.25 -K 0.25 -H 300 -V 300 Big-PlatMap.tif BigPlatMap-Tabloid.tif
The output images will have a specified resolution of 300 dpi in both directions. The orientation of each page will be determined by whichever choice requires the fewest pages. To specify a specific orientation, use the portrait or landscape option. The paper size option does not resample the image. It breaks each original image into a series of smaller images that will fit on the target paper size at the specified resolution.
Extract two regions 2048 pixels wide by 2048 pixels high from each page of a multi-page input file and write each region to a separate output file:
tiffcrop -U px -z 1,1,2048,2048:1,2049,2048,4097 -e separate CheckScans.tiff Check
The output file names will use the stem Check with a numeric suffix which is incremented for each region of each image, eg Check-001.tiff, Check-002.tiff … Check-NNN.tiff. To produce a unique file for each page of the input image with one new image for each region of the input image on that page change the export option to -e multiple.
In general, bilevel, grayscale, palette and RGB(A) data with bit depths from 1 to 32 bits should work in both interleaved and separate plane formats. Unlike tiffcp, tiffcrop can read and write tiled images with bits per sample that are not a multiple of 8 in both interleaved and separate planar format. Floating point data types are supported at bit depths of 16, 24, 32 and 64 bits per sample.
Not all images can be converted from one compression scheme to another. Data with some photometric interpretations and/or bit depths are tied to specific compression schemes and vice-versa, e.g. Group 3/4 compression is only usable for bilevel data. JPEG compression is only usable on 8 bit per sample data (or 12 bit if libtiff was compiled with 12 bit JPEG support). Support for OJPEG compressed images is problematic at best. Since OJPEG compression is no longer supported for writing images with LibTIFF, these images will be updated to the newer JPEG compression when they are copied or processed. This may cause the image to appear color shifted or distorted after conversion. In some cases, it is possible to remove the original compression from image data using the option -c none.
tiffcrop does not currently provide options to up or downsample data to different bit depths or convert data from one photometric interpretation to another, e.g. 16 bits per sample to 8 bits per sample or RGB to grayscale.
tiffcrop is very loosely derived from code in tiffcp with extensive modifications and additions to support the selection of input images and regions and the exporting of them to one or more output files in various groupings. The image manipulation routines are entirely new and additional ones may be added in the future. It will handle tiled images with bit depths that are not a multiple of eight that tiffcp may refuse to read.
tiffcrop was designed to handle large files containing many moderate sized images with memory usage that is independent of the number of images in the file. In order to support compression modes that are not based on individual scanlines, e.g. JPEG, it now reads images by strip or tile rather than by individual scanlines. In addition to the memory required by the input and output buffers associated with libtiff one or more buffers at least as large as the largest image to be read are required. The design favors large volume document processing uses over scientific or graphical manipulation of large datasets as might be found in research or remote sensing scenarios.
pal2rgb (1), tiffinfo (1), tiff2cmp (1), tiffcp (1), tiffmedian (1), tiffsplit (1), libtiff (3tiff)
LibTIFF contributors
1988-2023, LibTIFF contributors
November 23, 2023 | 4.5 |