Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

WRITE_TIFF


Syntax | Arguments | Keywords | Examples | Version History | See Also

The WRITE_TIFF procedure can write TIFF files with one or more channels, where each channel can contain 1, 4, 8, 16, or 32-bit integer pixels, or floating-point values.

Syntax

WRITE_TIFF, Filename [Image] [, /APPEND] [, BITS_PER_SAMPLE={1 | 4 | 8}] [, RED=value] [, GREEN=value] [, BLUE=value] [, COMPRESSION={0 | 2 | 3}] [, GEOTIFF=structure] [, /LONG | , /SHORT | , /FLOAT] [, ORIENTATION=value] [, PLANARCONFIG={1 | 2}] [, UNITS={1 | 2 | 3}] [, /VERBOSE] [, XRESOL=pixels/inch] [, YRESOL=pixels/inch]

Arguments

Filename

A scalar string containing the full pathname of the TIFF to write.

Image

The array to be written to the TIFF. If Image has dimensions (k,n,m), a k-channel TIFF is written. Image should be in top to bottom scan line order. By default, this array is converted to byte format before being written (see the LONG, SHORT and FLOAT keywords below). Note that many TIFF readers can read only one- or three-channel images.

Note
The Image argument is optional if PLANARCONFIG is set to 2 and the RED, GREEN, and BLUE keywords have been set to 2D arrays.

Note
Grayscale TIFF images are written out with the PhotometricInterpretation tag set to BlackIsZero, implying that values of 0 should correspond to black. If you want values of 0 to correspond to white, you should invert your pixel values before calling WRITE_TIFF.

Order

This argument is obsolete. The Order argument has been replaced by the ORIENTATION keyword. Code that uses the Order argument will continue to work as before, but new code should use the ORIENTATION keyword instead.

Keywords

APPEND

Set this keyword to specify that the image should be added to the existing file, creating a multi-image TIFF file.

BITS_PER_SAMPLE

Set this keyword to either 1, 4, or 8 to create a grayscale image file with the specified number of bits per pixel. For 1-bit (bi-level) images, an output pixel is assigned the value 1 (one) if the corresponding input pixel is nonzero. For 4-bit grayscale images, the input pixel values must be in the range 0 through 15, or the image will be garbled. The default is BITS_PER_SAMPLE=8. This keyword is ignored if an RGB image or color palette is present, or if one of the FLOAT, LONG, or SHORT keywords is set.

COMPRESSION

Set this keyword to select the type of compression to be used:

Note
For COMPRESSION=3 (JPEG), all images are assumed to be in top-to-bottom order, and the ORIENTATION keyword should not be specified. If your input image is not in top-to-bottom order, you should use REVERSE(image, 2) to flip the order before calling WRITE_TIFF.

FLOAT

Set this keyword to write the pixel components as floating-point entities (the default is 8-bit).

GEOTIFF

Set this keyword to an anonymous structure containing one field for each of the GeoTIFF tags and keys to be written into the file. The GeoTIFF structure is formed using fields named from the following table.

Anonymous Structure Field Name
IDLDatatype
TAGS:
"MODELPIXELSCALETAG"
DOUBLE[3]
"MODELTRANSFORMATIONTAG"
DOUBLE[4,4]
"MODELTIEPOINTTAG"
DOUBLE[6,*]
KEYS:
"GTMODELTYPEGEOKEY"
INT
"GTRASTERTYPEGEOKEY"
INT
"GTCITATIONGEOKEY"
STRING
"GEOGRAPHICTYPEGEOKEY"
INT
"GEOGCITATIONGEOKEY"
STRING
"GEOGGEODETICDATUMGEOKEY"
INT
"GEOGPRIMEMERIDIANGEOKEY"
INT
"GEOGLINEARUNITSGEOKEY"
INT
"GEOGLINEARUNITSIZEGEOKEY"
DOUBLE
"GEOGANGULARUNITSGEOKEY"
INT
"GEOGANGULARUNITSIZEGEOKEY"
DOUBLE
"GEOGELLIPSOIDGEOKEY"
INT
"GEOGSEMIMAJORAXISGEOKEY"
DOUBLE
"GEOGSEMIMINORAXISGEOKEY"
DOUBLE
"GEOGINVFLATTENINGGEOKEY"
DOUBLE
"GEOGAZIMUTHUNITSGEOKEY"
INT
"GEOGPRIMEMERIDIANLONGGEOKEY"
DOUBLE
"PROJECTEDCSTYPEGEOKEY"
INT
"PCSCITATIONGEOKEY"
STRING
"PROJECTIONGEOKEY"
INT
"PROJCOORDTRANSGEOKEY"
INT
"PROJLINEARUNITSGEOKEY"
INT
"PROJLINEARUNITSIZEGEOKEY"
DOUBLE
"PROJSTDPARALLEL1GEOKEY"
DOUBLE
"PROJSTDPARALLEL2GEOKEY"
DOUBLE
"PROJNATORIGINLONGGEOKEY"
DOUBLE
"PROJNATORIGINLATGEOKEY"
DOUBLE
"PROJFALSEEASTINGGEOKEY"
DOUBLE
"PROJFALSENORTHINGGEOKEY"
DOUBLE
"PROJFALSEORIGINLONGGEOKEY"
DOUBLE
"PROJFALSEORIGINLATGEOKEY"
DOUBLE
"PROJFALSEORIGINEASTINGGEOKEY"
DOUBLE
"PROJFALSEORIGINNORTHINGGEOKEY"
DOUBLE
"PROJCENTERLONGGEOKEY"
DOUBLE
"PROJCENTERLATGEOKEY"
DOUBLE
"PROJCENTEREASTINGGEOKEY"
DOUBLE
"PROJCENTERNORTHINGGEOKEY"
DOUBLE
"PROJSCALEATNATORIGINGEOKEY"
DOUBLE
"PROJSCALEATCENTERGEOKEY"
DOUBLE
"PROJAZIMUTHANGLEGEOKEY"
DOUBLE
"PROJSTRAIGHTVERTPOLELONGGEOKEY"
DOUBLE
"VERTICALCSTYPEGEOKEY"
INT
"VERTICALCITATIONGEOKEY"
STRING
"VERTICALDATUMGEOKEY"
INT
"VERTICALUNITSGEOKEY"
INT

Note
If a GeoTIFF key appears multiple times in a file, only the value for the first instance of the key is returned.

LONG

Set this keyword to write the pixel components as unsigned 32-bit entities (the default is 8-bit).

ORIENTATION

Set this keyword to an integer value to specify the orientation of the TIFF image. The default is ORIENTATION=1.

Note
For COMPRESSION=3 (JPEG), all images are assumed to be in top-to-bottom order, and this keyword should not be specified.

Possible values are:

Value
Description
0
Column 0 represents the left-hand side, and row 0 represents the bottom (same as 4)
1
Column 0 represents the left-hand side, and row 0 represents the top.
2
Column 0 represents the right-hand side, and row 0 represents the top.
3
Column 0 represents the right-hand side, and row 0 represents the bottom.
4
Column 0 represents the left-hand side, and row 0 represents the bottom (same as 0)
5
Column 0 represents the top, and row 0 represents the left-hand side.
6
Column 0 represents the top, and row 0 represents the right-hand side.
7
Column 0 represents the bottom, and row 0 represents the right-hand side.
8
Column 0 represents the bottom, and row 0 represents the left-hand side.

Warning
Not all TIFF readers honor the value of the ORIENTATION field. IDL writes the value into the file, but some readers are known to ignore this value. In such cases, we recommend that you convert the image to top-to-bottom order with the REVERSE function and then set ORIENTATION to 1.

PLANARCONFIG

This keyword determines the order in which a multi-channel image is stored and written. It has no effect with a single-channel image. Set this keyword to 2 to if the Image parameter is interleaved by "plane", or band, and its dimensions are (Columns, Rows, Channels). The default value is 1, indicating that multi-channel images are interleaved by color, also called channel, and its dimensions are (Channels, Columns, Rows).

As a special case, this keyword may be set to 2 to write an RGB image that is contained in three separate arrays (color planes), stored in the variables specified by the RED, GREEN, and BLUE keywords. Otherwise, omit this parameter (or set it to 1).

Note
Many TIFF readers can read only one- or three-channel images.

RED, GREEN, BLUE

If you are writing a Palette color image, set these keywords equal to the color table vectors, scaled from 0 to 255.

If you are writing an RGB interleaved image (i.e., if the PLANARCONFIG keyword is set to 2), set these keywords to the names of the variables containing the three image components.

SHORT

Set this keyword to write the pixel components as unsigned 16-bit entities (the default is 8-bit).

UNITS

Set this keyword to one of the following values to specify the units used for the values specified by the XRESOL and YRESOL keywords:

Value
Description
1
No units
2
Inches (the default)
3
Centimeters

VERBOSE

Set this keyword to produce additional diagnostic output during the write.

XRESOL

Set this keyword to the horizontal resolution, in pixels per unit, where the unit is specified by the value of the UNITS keyword (inches, by default). The default value of XRESOL is 100. Note that while this value is stored in the TIFF file, it may be interpreted by the TIFF reader in a variety of ways, or ignored.

YRESOL

Set this keyword to the vertical resolution, in pixels per unit, where the unit is specified by the value of the UNITS keyword (inches, by default). The default value of YRESOL is 100. Note that while this value is stored in the TIFF file, it may be interpreted by the TIFF reader in a variety of ways, or ignored.

Examples

Example 1

Create a pseudo screen dump from the current window. Note that this works only on a PseudoColor (8-bit) display:

WRITE_TIFF, 'test.tiff', TVRD() 

Example 2

Write a three-channel image from three one-channel (two-dimensional) arrays, contained in the variables Red, Green, and Blue:

WRITE_TIFF, 'test.tif', Red, Green, Blue, PLANARCONFIG=2 

Example 3

Write and read a multi-image TIFF file. The first image is a 16-bit single channel image stored using compression. The second image is an RGB image stored using 32-bits/channel uncompressed.

; Write the image data: 
data = FIX(DIST(256)) 
rgbdata = LONARR(3,320,240) 
WRITE_TIFF,'multi.tif',data,COMPRESSION=1,/SHORT 
WRITE_TIFF,'multi.tif',rgbdata,/LONG,/APPEND 
; Read the image data back 
ok = QUERY_TIFF('multi.tif',s) 
IF (ok) THEN BEGIN 
   FOR i=0,s.NUM_IMAGES-1 DO BEGIN 
      imp = QUERY_TIFF('multi.tif',t,IMAGE_INDEX=i) 
      img = READ_TIFF('multi.tif',IMAGE_INDEX=i) 
      HELP,t,/STRUCTURE 
      HELP,img 
   ENDFOR 
ENDIF 

Version History

Introduced: 5.0

ITIFF support added: 5.6

See Also

READ_TIFF, QUERY_* Routines


Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]