User's Guide

IMG2ASC

Write image values to an ASCII file

Function:

IMG2ASC converts LAS pixel values into ASCII format. It writes one record for each pixel, containing the x-coordinate or sample number for the pixel and the values for all bands. The y-coordinate or line number may be included in each record, or instead in a separate record at the beginning of data for each image line, depending on the value of argument RECSTRCT.

Parameters:

IN
Input LAS image. The name(s) and window(s) for the input LAS-format image(s).

OUT
Output ASCII file. The name of the file to receive the ASCII-format version of the image data.

HEADER(--)
Header text for output file. Text to be written at beginning of output file for identification. This will be followed by a blank line unless no header text is specified.

RECSTRCT("YOXV")
Structure of output records. The coordinates of each sample may be specified by (line number, sample number), (y-coordinate, x-coordinate) or (x-coordinate, y-coordinate). For the first two cases, the line number or y-coordinate may be repeated in each output record or written just once as a separate record. These options are specified by

    LSV	    Each output record includes line number, sample
            number, and value(s) for one sample.
    LOSV    For each image line, write line number only in one
            record, followed by one record for each sample on
            the line containing sample number and value(s).
    XYV     Each output record contains x-coordinate followed
            by y-coordinate and value(s) for one sample.
    YXV     Each output record contains y-coordinate followed
            by x-coordinate and value(s) for one sample.
    YOXV    For each image line, write y-coordinate only in one
            record, followed by one record for each sample on
            the line containing its x-coordinate and value(s).

COORFMT(".0F")
Format of coordinate fields. This defines the precision and, optionally, width of fields which specify coordinate values using C-language format-specification syntax. If two formats are entered, they apply to the first and second coordinate, as specified by argument RECSTRCT, respectively.

Permitted specifiers are d, e, f, and g. If a width specification is not entered explicitly, the minimum width needed to accommodate the maximum coordinate value will be used. This argument must be enclosed in quotes. Note that a specification of ".0f" will cause the value to be rounded to the nearest integer and output without the decimal point. Multiple fields in a record are separated by blanks.

VALFMT(--)
Format of pixel values. This defines the precision and, optionally, width of the fields which contain the pixel values using C-language format-specification syntax. Permitted specifiers are d, e, f, and g. If a width specification is not entered explicitly, the minimum width needed to accommodate the maximum coordinate value will be used. This argument must be enclosed in quotes. Note that a specification of ".0f" will cause the value to be rounded to the nearest integer and output without the decimal point. Multiple fields in a record are separated by blanks.

For integer data (data types BYTE, I*2, and I*4), the default is "d"; for floating point data (REAL*4), the default is to set the number of decimal places such that the largest values will retain 6 significant digits.

Examples:

  1. LAS> img2asc myimg myimg.ascii

    All bands of LAS image myimg.img are converted to ascii and written to file myimg.ascii. No header record is written. The records containing data for each image line are preceded by a separate record containing the map-projection y-coordinate for that line. The record for each pixel contains the x-coordinate followed by the values for each band. The coordinates are rounded to the nearest integer. If the data type is REAL, the pixel values will be written with two decimal places.

  2. LAS> img2asc in="myimg2(51, 101, 20, 30: 1-4, 6)" out=myimg2.ascii header="myimg2, bands 1-4 and 6" recstrct=xyv coorfmt="12.2f" valfmt="12.6e"

    Bands 1-4 and 6 of the specified window of LAS image myimg2.img are converted to ascii and written to file myimg2.ascii. The specified header is written, followed by a blank line. One record is written for each pixel, containing the map-projection x-coordinate and y-coordinate, both carried to 2 decimal places, followed by the pixel values for bands 1, 2, 3, 4, and 6 rounded to 7 significant figures. All fields are 12 characters wide, with single spaces between successive fields.

Description/Algorithm:

IMG2ASC begins by getting the program arguments. It then reads the input-image DDR to get projection coordinates, if needed, and computes the maximum and minimum x- and y-coordinates or line and sample numbers for the specified input window. The band-dependent DDR records are read to determine the maximum and minimum pixel values for all the bands to be precessed. These values are then combined with the COORFMT and VALFMT arguments to determine the maximum field width and output format for the pixel coordinates and pixel values.

The input and output files are opened, and the header record, if any, is written to the output. All lines within the input window are then processed one at a time, converting the output to ASCII format as specified by the RECSTRCT argument, using the previously computed field widths.

Nonfatal Error Messages:

  1. [img2asc-diffdtype] "Input image <image-1> has differenct data type than <image-2> -- all input images will be converted to <datatype>"

    The images in the input image set do not all have the same datatype. The output datatype will be determined by the image having the "highest" data type, in the order BYTE < INTEGER*2 < INTEGER*4 < REAL*4.

  2. [img2asc-usecoord] "Image <image-1> lacks coordinate data -- using data for image <image-2>"

    Some, but not all, of the images in an input image set lack valid corner-coordinate data in the DDR. The coordinates for the first image with valid data will be used to compute pixel coordinates for the output file.

  3. [img2asc-misreg] "Warning: window for <image-2> is out of registration with <image-1> by more than 0.5 pixels"

    The corner coordinates of the windows specified for two images in an input image set are not the same. The coordinates for <image-1> will be to compute pixel coordinates for the output file.

  4. [img2asc-minmax] "Invalid min/max for <image-name>, band <band>"

    The entries in the DDR file for the specified band(s) do not contain valid minimum and maximum pixel values. The maximum required field width for writing pixels values to the output file will be determined from the band(s) for which valid minimum and maximum values are available. An output file will be generated, but if the band(s) lacking max/min data contain larger values, the output column widths may be uneven. The minimum/maximum values can be set by running program MINMAX on the input image(s).

  5. [img2asc-nocheck] "Cannot check whether field width is sufficient"

    The DDR entries for one or more bands do not contain valid maximum and minimum pixel values. Since it is therefore not possible to compute the maximum required output width, the user-requested field width has not been checked to see whether it is sufficient. An output file will be generated, but if the requested field width is too small, the output column widths may be uneven. The minimum/maximum values can be set by running program MINMAX on the input image(s).

Fatal Error Messages:

  1. [img2asc-fatal] "Aborting on fatal error"

    Processing could not continue for the reason given in the message(s) written out before this one.

  2. [img2asc-badwind] "Input image windows not all same size"

    When an input image set is specified, all images must have same size window. Correct the window specification(s) and rerun the program.

  3. [img2asc-nocoord] "Coordinate information for input image(s) not valid; cannot use RECSTRCT = <recstrct>"

    The requested record structure <recstrct> requires x- and y-coordinates for each pixel, but the input image DDR files do not contain corner-coordinate information flagged as "VALID". Either enter correct data into the DDR (using EDITDDR) or specify a different output record structure.

  4. [img2asc-diffwind] "Input images have different window upper-left corners -- using line and sample numbers from first image"

    Although the images in the input image set all have the same window size, the starting line and/or sample values are not all the same. The line and sample numbers for the first input image will be used to identify pixel locations in the output file.

  5. [img2asc-badwidth] "Requested field width = <width> for <variable> is less than required width = <width>"

    The width specified by argument COORFMT or VALFMT is not sufficient to accommodate the minimum or maximum value of the variable. Rerun the program with a larger field width.

  6. [img2asc-malloc] "Error allocating array space"

    The program could not allocate space for working arrays. This is probably a program or system error -- notify the LAS support personnel.

  7. [img2asc-openout] "Error opening output file: <reason>"

    The output file could not be opened for the reason specified. Correct the OUT argument or use CHDIR to change the current working directory.

  8. [img2asc-write] "Error writing to output: <reason>"

    The specified error occurred while writing to the output file. If the file system is full or disk quota exceeded, either delete other files or change to a different file system. Otherwise, there may be a system problem -- notify the LAS support personnel.

User Note:

  1. A format specification for COORFMT or VALFMT which ends with ".0f" will cause the values to be rounded to the nearest integer and output without a decimal point.