Tips and Pitfalls

Image I/O

Perhaps the most confusing aspect of image I/O is the rather unintuitive way images are written in imio. It is necessary to obtain an output pointer using one of the imp... procedures and then filling in the values in the output buffer. The pixels are not actually written to the output file until the output buffer is flushed or the image is closed. This can, in fact, lead to another pitfall. If you wish to write and read the same image in the same task, you must be sure that the pixels are written out before trying to read them in again. This may be assured with a call to imflush() after filling the output buffer. Alternately, you might close the image using imunmap() and then reopen it with immap(). A brief example may clarify this situation. The following fragment of code opens an image for read and write access, writes some pixels and reads them back in.

If you read two lines using arbitrary line I/O with two separate buffer pointers, the second call may make the first pointer x1 invalid.

x1 = imgl2r (im, i) 
x2 = imgl2r (im, i+1) 
This applies to output, impl2T() as well as input.

Group Format

One additional wrinkle involves multi-image group format STF (STSDAS*1 format) images. This format allows more than one image in a single logical image (pair of files; header and pixel file) with a common image header. It is possible to access more than one image in the group simultaneously in a task. With imio, each sub-image (sometimes referred to confusingly as a group) you need to use immap() separately. To specify which image in the set to open, append the image number enclosed in square brackets to the file name in the immap() call. The following opens the second image in a multi-image group format file:

In many cases, it would be up to the user to specify the group number on the image file name when using the task. There may be cases, however, in which a task would use specific groups in an image. To create a new multi-image file, you must specify the total number of images in the set as well as the image number. Example C.14 creates a four image set and opens the first image.

A slight complication arises when you wish to create a multi-image group format file and simultaneously access more than one image. In this case, you must create the image, close it, and reopen the individual images. Note also that the pixel file will not be created propeunless a write operation is performed. This may be done by simply writing a single line before closing the image.

Group Format

Generated with CERN WebMaker