Image I/O Routines

The image I/O service routines are called by any application program that does image processing.

The image I/O routines were developed to read and/or write image data. All application programs that do image processing will call a subset of these routines.

There are two ways to access an image in LAS. An image can be accessed sequentially or randomly. Each processing method is described in the next two sections: Random Image Processing and Sequential Image Processing.

A program can access the image I/O routines by linking in the following object library:

     $LASLIB/las.a  

Random Image Processing

Processing of images in a random manner is fairly straightforward. Each image (whether input or output) is opened by calling c_eopenr(). Individual lines, bands, and images are accessed with calls to c_eread() and c_ewrite(). The files are closed by calling c_eclose() once for each image.

A buffer for the random calls must either be allocated ahead of time by FORTRAN or C--or can be dynamically allocated in a C program by use of malloc routines. The allocated buffer must be large enough to hold at least one line of data (maximum number of samples times data type size).

If acc=IUPDATE, then c_ewrite() must be called to copy the buffer back to the file being updated before subsequent calls to c_eread(). Note that random image processing is faster than sequential image processing. In addition, there is no real limit to the number of bands that can be processed with random image processing.

Sequential Image Processing

To process images sequentially, several calls are made to the subroutine c_eopens(), one for each input or output image. Each image in LAS can contain several bands although the number of images open at once is limited by the amount of buffer space available. After the calls to c_eopens(), the images can be grouped into collections of images. The images are grouped so that a call to c_estep() will read in a line from each band of each input image and write a line for each band of the output image. c_estep() is called for every line processed. It is also called once at the beginning of processing to read in the first line of each input image and to reserve space for the first line of each band of the output image. When sequential processing is done, a call to c_egclse() for each group of images will close all the images in each group.

A buffer for the sequential calls must either be allocated ahead of time by FORTRAN or C. The buffer for this type of allocation must be large enough to hold at least one line of data (maximum number of samples times data type size). If the routine is being written in C, then the buffer can be dynamically allocated using the c_ealloc() function.

Note that with sequential image processing there is a limit to the number of bands and/or image size before running out of buffer space.

Example using sequential imageio (written in 'C'):

/* Open input image(s)
----------------------*/
access = IREAD;
opt[0] = 0;
opt[1] = 0;

for (band=0, image=0; image < nmrimg; image++)
    {
    status = c_eopens(&fdesc[image], hosin[image], bands[image], &sl, &ss,
	&nl, &ns, &offset1[band], &access, &odtype, &zero, &opt);
    band += nbands[image];
    }

/* Open output image
--------------------*/
access = IWRITE; 
status = c_eopens(&fdesc[nmrimg], hosout, &totbnd, &one, &one, &nl, &ns,
    offset2, &access, &odtype, &zero, &opt);
fdesc[nmrimg+1] = 0;

/* Allocate I/O buffer 'C' only
-------------------------------*/
thebuf = c_ealloc(fdesc, &bufsiz);

/* Group images
---------------*/ 
c_egroup(fdesc, &gdesc, thebuf, &bufsiz);

/* Main processing loop
-----------------------*/
for (curlin=0; curlin < nl; curlin++)
    {
    status = c_estep(&gdesc);
    for (band=0; band < totbnd; band++)
	{
	/* DESIRED PROCESSING */
	}
    }

/* Final write
--------------*/
status = c_estep(&gdesc);

/* Close all image files in the group
-------------------------------------*/
status = c_egclse(&gdesc);

/* Free buffer
--------------*/
free(thebuf);

This is a list of available Image I/O Routines:

ealloc.html
eclose.html
egclse.html
egroup.html
eopenr.html
eopens.html
eread.html
estep.html
ewrite.html
get_buf.html
put_buf.html