Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/doc/tools/tiffcrop.rst

raw
1 tiffcrop
2 ========
3
4 .. program:: tiffcrop
5
6 Synopsis
7 --------
8
9 **tiffcrop** [ *options* ] *src1.tif* … *srcN.tif* *dst.tif*
10
11 Description
12 -----------
13
14 :program:`tiffcrop` processes one or more files created according
15 to the Tag Image File Format, Revision 6.0, specification
16 into one or more TIFF file(s).
17 :program:`tiffcrop` is most often used to extract portions of an image for processing
18 with bar code recognizer or OCR software when that software cannot
19 restrict the region of interest to a specific portion of the image
20 or to improve efficiency when the regions of interest must be rotated.
21 It can also be used to subdivide all or part of a processed image into
22 smaller sections and export individual images or sections of images
23 as separate files or separate images within one or more files derived
24 from the original input image or images.
25
26 The available functions can be grouped broadly into three classes:
27
28 #. Those that select individual images or sections of images from the input files.
29 The options :option:`-N` for sequences or lists of individual images in the input files,
30 :option:`-Z` for zones, :option:`-z` for regions, :option:`-X` and :option:`-Y` for fixed sized selections,
31 :option:`-m` for margins, :option:`-U` for units, and :option:`-E` for edge reference provide a variety of
32 ways to specify portions of the input image.
33
34 #. Those that allow the individual images or selections to be exported to one or
35 more output files in different groupings and control the organization of the
36 data in the output images. The options :option:`-P` for page size grouping, :option:`-S` for
37 subdivision into columns and rows and :option:`-e` for export mode options that produce
38 one or more files from each input image. The options :option:`-r`, :option:`-s`, :option:`-t`, :option:`-w` control
39 strip and tile format and sizes while :option:`-B`, :option:`-L`, :option:`-c`, :option:`-f` modify the endian addressing
40 scheme, the compression options, and the bit fill sequence of images as they
41 are written.
42
43 #. Those that perform some action on each image that is selected from the input file.
44 The options include :option:`-R` for rotate, :option:`-I` for inversion of the photometric
45 interpretation and/or data values, and :option:`-F` to flip (mirror) the image horizontally
46 or vertically.
47
48 Functions are applied to the input image(s) in the following order:
49 cropping, fixed area extraction, zone and region extraction,
50 inversion, mirroring, rotation.
51
52 Functions are applied to the output image(s) in the following order:
53 export mode options for grouping zones, regions, or images into
54 one or more files, *or* row and column divisions with output margins,
55 *or* page size divisions with page orientation options.
56
57 Finally, strip, tile, byte order, output resolution, and compression options are
58 applied to all output images.
59
60 The output file(s) may be organized and compressed using a different
61 algorithm from the input files.
62 By default, :program:`tiffcrop` will copy all the understood tags in a TIFF
63 directory of an input file to the associated directory in the output file.
64 Options can be used to force the resultant image to be written as strips
65 or tiles of data, respectively.
66
67 :program:`tiffcrop` can be used to reorganize the storage characteristics of data
68 in a file, and to reorganize, extract, rotate, and otherwise
69 process the image data as specified at the same time whereas
70 :program:`tiffcp` does not alter the image data within the file.
71
72 Using the options for selecting individual input images and the
73 options for exporting images and/or segments defined as zones or
74 regions of each input image, :program:`tiffcrop` can perform the
75 functions of :program:`tiffcp` and :program:`tiffsplit` in a single pass
76 while applying multiple operations to individual selections or images.
77
78 Options
79 -------
80
81 .. option:: -h
82
83 Display the syntax summary for tiffcrop.
84
85 .. option:: -v
86
87 Report the current version and last modification date for tiffcrop.
88
89 .. option:: -N odd|even|#,#-#,#|last
90
91 Specify one or more series or range(s) of images within each file to process.
92 The words ``odd`` or ``even``
93 may be used to specify all odd or even numbered images counting from one.
94 Note that internally, TIFF images are numbered from zero rather than one
95 but since this convention is not obvious to most users, :program:`tiffcrop` used 1
96 to specify the first image in a multipage file. The word ``last``
97 may be used in place of a number in the sequence to indicate the
98 final image in the file without knowing how many images there are.
99 Ranges of images may be specified with a dash and multiple sets
100 can be indicated by joining them in a comma-separated list. eg. use
101 ``-N 1,5-7,last``
102 to process the 1st, 5th through 7th, and final image in the file.
103
104 .. option:: -E top|bottom|left|right
105
106 Specify the ``top``, ``bottom``, ``left``, or ``right`` edge as the reference from
107 which to calculate the width and length of crop regions or sequence
108 of positions for zones. When used with the :option:`-e` option for exporting
109 zones or regions, the reference edge determines how composite images
110 are arranged. Using ``-E left`` or ``-E right`` causes successive zones or
111 regions to be merged horizontally whereas using ``-E top`` or ``-E bottom``
112 causes successive zones or regions to be arranged vertically. This
113 option has no effect on export layout when multiple zones or regions
114 are not being exported to composite images. Edges may be abbreviated
115 to the first letter.
116
117 .. option:: -e combined|divided|image|multiple|separate
118
119 Specify the export mode for images and selections from input images.
120 The final filename on the command line is considered to be the
121 destination file or filename stem for automatically generated
122 sequences of files. Modes may be abbreviated to the first letter.
123
124 .. list-table:: Export modes
125 :widths: 5 20
126 :header-rows: 1
127
128 * - Export mode
129 - Description
130
131 * - combined
132 - All images and selections are written to a single file with
133 multiple selections from one image combined into a single image (default)
134 * - divided
135 - All images and selections are written to a single file
136 with each selection from one image written to a new image
137 * - image
138 - Each input image is written to a new file (numeric filename sequence)
139 with multiple selections from the image combined into one image
140 * - multiple
141 - Each input image is written to a new file (numeric filename sequence)
142 with each selection from the image written to a new image
143 * - separate
144 - Individual selections from each image are written to separate files
145
146 .. option:: -U in|cm|px
147
148 Specify the type of units to apply to dimensions for margins and
149 crop regions for input and output images. Inches or centimeters
150 are converted to pixels using the resolution unit specified in the
151 TIFF file (which defaults to inches if not specified in the IFD).
152
153 .. option:: -m top,left,bottom,right
154
155 Specify margins to be removed from the input image. The order must
156 be *top*, *left*, *bottom*, *right* with only commas separating the elements
157 of the list. Margins are scaled according to the current units and
158 removed before any other extractions are computed.
159
160 .. option:: -X #
161
162 Set the horizontal (X-axis) dimension of a region to extract relative to
163 the specified origin reference. If the origin is the top or bottom
164 edge, the X axis value will be assumed to start at the left edge.
165
166 .. option:: -Y #
167
168 Set the vertical (Y-axis) dimension of a region to extract relative to
169 the specified origin reference. If the origin is the left or right
170 edge, the Y axis value will be assumed to start at the top.
171
172 .. option:: -Z #:#,#:#
173
174 Specify zones of the image designated as position X of Y equal sized portions
175 measured from the reference edge, eg 1:3 would be first third of the
176 image starting from the reference edge minus any margins specified
177 for the confining edges. Multiple zones can be specified as a comma
178 separated list but they must reference the same edge. To extract the
179 top quarter and the bottom third of an image you would use
180 ``-Z 1:4,3:3``.
181
182 .. option:: -z x1,y1,x2,y2: ... :xN,yN,xN+1,yN+1
183
184 Specify a series of coordinates to define regions for processing and exporting.
185 The coordinates represent the top left and lower right corners of each region
186 in the current units, eg inch, cm, or pixels. Pixels are counted from one to
187 width or height and inches or cm are calculated from image resolution data.
188
189 Each colon delimited series of four values represents the horizontal and vertical
190 offsets from the top and left edges of the image, regardless of the edge specified
191 with the :option:`-E` option. The first and third values represent the horizontal offsets of
192 the corner points from the left edge while the second and fourth values represent
193 the vertical offsets from the top edge.
194
195 .. option:: -F horiz|vert
196
197 Flip, ie mirror, the image or extracted region horizontally or vertically.
198
199 .. option:: -R 90|180|270
200
201 Rotate the image or extracted region 90, 180, or 270 degrees clockwise.
202
203 .. option:: -I [black|white|data|both]
204
205 Invert color space, eg dark to light for bilevel and grayscale images.
206 This can be used to modify negative images to positive or to correct
207 images that have the ``PHOTOMETRIC_INTERPRETATION`` tag set incorrectly.
208 If the value is black or white, the ``PHOTOMETRIC_INTERPRETATION`` tag is set to
209 MinIsBlack or MinIsWhite, without altering the image data. If the argument
210 is data or both, the data values of the image are modified. Specifying both
211 inverts the data and the ``PHOTOMETRIC_INTERPRETATION`` tag, whereas using data
212 inverts the data but not the ``PHOTOMETRIC_INTERPRETATION`` tag.
213 No support for modifying the color space of color images in this release.
214
215 .. option:: -H #
216
217 Set the horizontal resolution of output images to *#*,
218 expressed in the current units.
219
220 .. option:: -V #
221
222 Set the vertical resolution of the output images to *#*
223 expressed in the current units.
224
225 .. option:: -J #
226
227 Set the horizontal margin of an output page size to *#*
228 expressed in the current units when sectioning image into *columns* × *rows*
229 subimages using the :option:`-S` ``cols:rows`` option.
230
231 .. option:: -K #
232
233 Set the vertical margin of an output page size to *#*
234 expressed in the current units when sectioning image into *columns* × *rows*
235 subimages using the :option:`-S` ``cols:rows`` option.
236
237 .. option:: -O portrait|landscape|auto
238
239 Set the output orientation of the pages or sections.
240 Auto will use the arrangement that requires the fewest pages.
241 This option is only meaningful in conjunction with the :option:`-P`
242 option to format an image to fit on a specific paper size.
243
244 .. option:: -P page
245
246 Format the output images to fit on page size paper. Use
247 ``-P list`` to show the supported page sizes and dimensions.
248 You can define a custom page size by entering the width and length of the
249 page in the current units with the following format ``#.#x#.#``.
250
251 .. option:: -S cols:rows
252
253 Divide each image into cols across and rows down equal sections.
254
255 .. option:: -B
256
257 Force output to be written with Big-Endian byte order.
258 This option only has an effect when the output file is created or
259 overwritten and not when it is appended to.
260
261 .. option:: -C
262
263 Suppress the use of "strip chopping" when reading images
264 that have a single strip/tile of uncompressed data.
265
266 .. option:: -c
267
268 Specify the compression to use for data written to the output file:
269 :command:`-c none` for no compression,
270 :command:`-c packbits` for PackBits compression,
271 :command:`-c lzw` for Lempel-Ziv & Welch compression,
272 :command:`-c jpeg` for baseline JPEG compression.
273 :command:`-c zip` for Deflate compression,
274 :command:`-c g3` for CCITT Group 3 (T.4) compression,
275 :command:`-c g4` for CCITT Group 4 (T.6) compression.
276 By default :program:`tiffcrop` will compress data according to the value of the
277 ``Compression`` tag found in the source file.
278
279 The CCITT Group 3 and Group 4 compression algorithms can only
280 be used with bilevel data.
281
282 Group 3 compression can be specified together with several
283 T.4-specific options:
284 ``1d`` for 1-dimensional encoding,
285 ``2d`` for 2-dimensional encoding,
286 ``fill`` to force each encoded scanline to be zero-filled so that the
287 terminating EOL code lies on a byte boundary.
288 Group 3-specific options are specified by appending a ``:``-separated
289 list to the ``g3`` option; e.g. ``-c g3:2d:fill``
290 to get 2D-encoded data with byte-aligned EOL codes.
291
292 LZW compression can be specified together with a ``predictor``
293 value. A predictor value of 2 causes
294 each scanline of the output image to undergo horizontal
295 differencing before it is encoded; a value
296 of 1 forces each scanline to be encoded without differencing.
297 LZW-specific options are specified by appending a ``:``-separated
298 list to the ``lzw`` option; e.g. ``-c lzw:2`` for LZW
299 compression with horizontal differencing.
300
301 .. option:: -f
302
303 Specify the bit fill order to use in writing output data.
304 By default, :program:`tiffcrop`
305 will create a new file with the same fill order as the original.
306 Specifying
307 ``-f lsb2msb``
308 will force data to be written with the ``FillOrder`` tag set to
309 ``LSB2MSB``, while
310 ``-f msb2lsb`` will force data to be written with the ``FillOrder``
311 tag set to ``MSB2LSB``.
312
313 .. option:: -i
314
315 Ignore non-fatal read errors and continue processing of the input file.
316
317 .. option:: -k size
318
319 Set maximum memory allocation size (in MiB). The default is 256MiB.
320 Set to 0 to disable the limit.
321
322 .. option:: -l
323
324 Specify the length of a tile (in pixels).
325 :program:`tiffcrop` attempts to set the tile dimensions so
326 that no more than 8 kilobytes of data appear in a tile.
327
328 .. option:: -L
329
330 Force output to be written with Little-Endian byte order.
331 This option only has an effect when the output file is created or
332 overwritten and not when it is appended to.
333
334 .. option:: -M
335
336 Suppress the use of memory-mapped files when reading images.
337
338 .. option:: -p
339
340 Specify the planar configuration to use in writing image data
341 that has more than one sample per pixel.
342 By default, :program:`tiffcrop`
343 will create a new file with the same planar configuration as
344 the original.
345 Specifying :command:`-p contig`
346 will force data to be written with multi-sample data packed
347 together, while
348 :command:`-p separate`
349 will force samples to be written in separate planes.
350
351 .. option:: -r
352
353 Specify the number of rows (scanlines) in each strip of data
354 written to the output file.
355 By default (or when value **0** is specified), :program:`tiffcrop`
356 attempts to set the rows/strip that no more than 8 kilobytes of
357 data appear in a strip. If you specify the special value
358 **-1** it will results in infinite number of the rows per strip. The entire image
359 will be the one strip in that case.
360
361 .. option:: -s
362
363 Force the output file to be written with data organized in strips
364 (rather than tiles).
365
366 .. option:: -t
367
368 Force the output file to be written with data organized in tiles
369 (rather than strips).
370
371 .. option:: -w
372
373 Specify the width of a tile (in pixels).
374 :program:`tiffcrop` attempts to set the tile dimensions so
375 that no more than 8 kilobytes of data appear in a tile.
376
377 .. option:: -D opt1:value1,opt2:value2,opt3:value3:opt4:value4
378
379 Debug and dump facility
380
381 Display program progress and/or dump raw data to non-TIFF files.
382 Options include the following and must be joined as a comma
383 separated list. The use of this option is generally limited to
384 program debugging and development of future options. An equal sign
385 may be substituted for the colon in option:value pairs.
386
387 ``debug:N``:
388
389 Display limited program progress indicators where larger *N*
390 increases the level of detail.
391
392 ``format:txt|raw``:
393
394 Format any logged data as ASCII text or raw binary
395 values. ASCII text dumps include strings of ones and zeroes representing
396 the binary values in the image data plus identifying headers.
397
398 ``level:N``:
399
400 Specify the level of detail presented in the dump files.
401 This can vary from dumps of the entire input or output image data to dumps
402 of data processed by specific functions. Current range of levels is 1 to 3.
403
404 ``input:full-path-to-directory/input-dumpname``:
405
406 ``output:full-path-to-directory/output-dumpname``:
407
408 When dump files are being written, each image will be written to a separate
409 file with the name built by adding a numeric sequence value to the dumpname
410 and an extension of :file:`.txt` for ASCII dumps or :file:`.bin` for binary dumps.
411
412 The four debug/dump options are independent, though it makes little sense to
413 specify a dump file without specifying a detail level.
414
415 Note: :program:`tiffcrop` may be compiled with :command:`-DDEVELMODE` to enable
416 additional very low level debug reporting.
417
418 However, not all option combinations are permitted.
419
420 Note 1: The (-X|-Y), -Z, -z and -S options are mutually exclusive.
421 In no case should the options be applied to a given selection successively.
422
423 Note 2: Any of the -X, -Y, -Z and -z options together with other PAGE_MODE_x options
424 such as -H, -V, -P, -J or -K are not supported and may cause buffer overflows.
425
426 Examples
427 --------
428
429 The following concatenates two files and writes the result using LZW
430 encoding:
431
432 .. highlight:: shell
433
434 ::
435
436 tiffcrop -c lzw a.tif b.tif result.tif
437
438 To convert a G3 1d-encoded TIFF to a single strip of G4-encoded data the following might be used:
439
440 ::
441
442 tiffcrop -c g4 -r 10000 g3.tif g4.tif
443
444 (1000 is just a number that is larger than the number of rows in
445 the source file.)
446
447 To extract a selected set of images from a multi-image TIFF file
448 use the :option:`-N` option described above. Thus, to copy the 1st and 3rd
449 images of image file :file:`album.tif` to :file:`result.tif`:
450
451 ::
452
453 tiffcrop -N 1,3 album.tif result.tif
454
455 Invert a bilevel image scan of a microfilmed document and crop off margins of
456 0.25 inches on the left and right, 0.5 inch on the top, and 0.75 inch on the
457 bottom. From the remaining portion of the image, select the second and third
458 quarters, ie, one half of the area left from the center to each margin:
459
460 ::
461
462 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
463
464 Extract only the final image of a large Architectural E sized
465 multipage TIFF file and rotate it 90 degrees clockwise while
466 reformatting the output to fit on tabloid sized sheets with one
467 quarter of an inch on each side:
468
469 ::
470
471 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
472
473 The output images will have a specified resolution of 300 dpi in both
474 directions. The orientation of each page will be determined by whichever
475 choice requires the fewest pages. To specify a specific orientation, use
476 the portrait or landscape option. The paper size option does not resample
477 the image. It breaks each original image into a series of smaller images
478 that will fit on the target paper size at the specified resolution.
479
480 Extract two regions 2048 pixels wide by 2048 pixels high from each page of
481 a multi-page input file and write each region to a separate output file:
482
483 ::
484
485 tiffcrop -U px -z 1,1,2048,2048:1,2049,2048,4097 -e separate CheckScans.tiff Check
486
487 The output file names will use the stem :file:`Check` with a numeric suffix which is
488 incremented for each region of each image, eg :file:`Check-001.tiff`,
489 :file:`Check-002.tiff` … :file:`Check-NNN.tiff`. To produce a unique file for each page
490 of the input image with one new image for each region of the input image on that page
491 change the export option to ``-e multiple``.
492
493 Notes
494 -----
495
496 In general, bilevel, grayscale, palette and RGB(A) data with bit depths
497 from 1 to 32 bits should work in both interleaved and separate plane
498 formats. Unlike :program:`tiffcp`, :program:`tiffcrop` can read and write tiled images with
499 bits per sample that are not a multiple of 8 in both interleaved and
500 separate planar format. Floating point data types are supported at
501 bit depths of 16, 24, 32 and 64 bits per sample.
502
503 Not all images can be converted from one compression scheme to another.
504 Data with some photometric interpretations and/or bit depths are tied to
505 specific compression schemes and vice-versa, e.g. Group 3/4 compression
506 is only usable for bilevel data. JPEG compression is only usable on 8
507 bit per sample data (or 12 bit if :program:`libtiff`
508 was compiled with 12 bit JPEG support). Support for OJPEG compressed
509 images is problematic at best. Since OJPEG compression is no longer
510 supported for writing images with LibTIFF, these images will be updated
511 to the newer JPEG compression when they are copied or processed. This
512 may cause the image to appear color shifted or distorted after conversion.
513 In some cases, it is possible to remove the original compression from
514 image data using the option ``-c none``.
515
516 :program:`tiffcrop` does not currently provide options to up or downsample data to
517 different bit depths or convert data from one photometric interpretation
518 to another, e.g. 16 bits per sample to 8 bits per sample or RGB to grayscale.
519
520 :program:`tiffcrop` is very loosely derived from code in :program:`tiffcp`
521 with extensive modifications and additions to support the selection of input
522 images and regions and the exporting of them to one or more output files in
523 various groupings. The image manipulation routines are entirely new and
524 additional ones may be added in the future. It will handle tiled images with
525 bit depths that are not a multiple of eight that tiffcp may refuse to read.
526
527 :program:`tiffcrop` was designed to handle large files containing many moderate sized images
528 with memory usage that is independent of the number of images in the file.
529 In order to support compression modes that are not based on individual
530 scanlines, e.g. JPEG, it now reads images by strip or tile rather than by
531 individual scanlines. In addition to the memory required by the input and
532 output buffers associated with :program:`libtiff`
533 one or more buffers at least as large as the largest image to be read are
534 required. The design favors large volume document processing uses over
535 scientific or graphical manipulation of large datasets as might be found
536 in research or remote sensing scenarios.
537
538 See also
539 --------
540
541 :doc:`pal2rgb` (1),
542 :doc:`tiffinfo` (1),
543 :doc:`tiffcmp` (1),
544 :doc:`tiffcp` (1),
545 :doc:`tiffmedian` (1),
546 :doc:`tiffsplit` (1),
547 :doc:`/functions/libtiff` (3tiff)