Image Plots
1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup
21: Concept Index
|
9: Image Plots
Gri can read in images stored in various formats. It can also create
image data internally, by converting gridded data, which is quite handy
in some contouring applications.
Note: if your diagram is to be reproduced by a journal, it is unlikely
that the reproduction will be able to distinguish between any two
graylevels which differ by less than 0.2. Also, graylevels less than
0.2 may appear as pure black, while those of 0.8 or more may appear as
pure white. These guidelines are as specified by American Geophysical
Union (publishers of J. Geophysical Res.), as of 1998.
9.1: Reading and Creating Image Data
Gri can do black and white image plots, such as satellite images. There
are several ways to create image data in Gri
-
Create images from gridded data using `
convert grid to image '. For
examples see Grayscale Images,
see Combination,
and see Contouring.
-
Read raw ascii image data files. Use `
read grid '.
-
Read PGM (portable graymap) ascii files. (That is, a file with magic
characters `
P1 ' or `P3 ' at the start.) Use the
`read image pgm ' command, for a file opened in ascii mode with
`open filename '.
-
Read raw binary data, with or without headers. Use `
read image ',
after skipping any header bytes using the `skip ' command, for a
file opened in binary mode with `open filename binary '.
-
Read a Sun ``rasterfile'' file (but only in uncompressed form). Use
`
read image rasterfile ' for a file opened in binary mode with
`open filename binary '.
-
Read a PGM (portable graymap) binary file. (A file with magic
characters `
P2 ' or `P4 ' at the start.) Use the
`read image pgm ' for a file opened in binary mode with
`open filename binary '.
-
Aside: Images can be converted to grids (for contouring) using
`
convert image to grid ' see Convert.
Once the image is created, it's grayscale/colorscale may be manipulated
with the commands `set image grayscale ' and
`set image colorscale ', which permit linear and histogram-equalized
blendings over the grayscale or color range, or with
`read image grayscale ' and
`read image colorscale ', which permit reading in the grayscale or
color values individually, one for each of the 256 pixel values.
It is important to understand the structure of image data. Gri works
only with 8-bit image data. This means that a given pixel of the image
may have only one of 256 possible values. The example below uses a
satellite image of surface temperature. The suppliers of the data
dictate that pixel value 0 corresponds to a temperature of 5C, and a
pixel value of 255 corresponds to 30.5C, so the resolution is 0.1C per
pixel value. This resolution will be apparent if the output of the
example below is previewed on a grayscale/color monitor --- notice the
quantization in the palette. This resolution issue is not very
important with satellite images, since you have to use what you are
given by the suppliers of the data. However, issue is very important
when you are converting grid data to images. When Gri converts grid
data to image data, it neccessarily discards information, because the
grid data have resolution to about 6 digits, whereas the image data have
only 8-bit (2-3 digit) resolution. The `set image range ' commands
determines the range of this 8-bit resolution in terms of user units.
All other things being equal, it would be preferable to use the smallest
range consistent with the range of your data. If your grid data ranged
from 0 to 1, say, you might `set image range 0 1 '. This would give
a resolution in the image of 1/255 in the user units. But, when Gri
converts the grid into an image, it will clip all data outside
the indicated range. In this case, any data greater than 1 in the grid
would translate to exactly 1 in the image. Naturally there is a
tradeoff between having a range large enough to encompass any data in
the grid, and a range small enough to yield adequate resolution. In
most cases, 8-bit resolution will be adequate, but it is good to be
aware of the limitations. One should always `draw image palette ',
and check it on a color monitor for bandedness, which is a sign of
resolution problems.
9.2: About The PostScript Output
Programmers Note: Gri inserts some special comments in the PostScript
file, to help programmers extract the image data; to extract the
information, you'll have to understand how PostScript handles images.
Gri inserts a single comment line before a line ending in the token
`im ':
%BEGIN_IMAGE
170.70 170.70 534.86 534.86 128 128 im
|
The first four numbers are the (x,y) locations of the lower-left and
upper-right corners of the image, in units of points on the page (72
points = 1 inch). The fifth and sixth numbers are the width of the
image and the height of the image. The keyword `im ' is always
present on this line. Gri inserts the following comment line at the end
of the image data:
A program is provided with Gri to extract these images into a binary
format suitable for viewing and manipulating with standard tools
see Extractor Of Images.
9.3: Example (Satellite image)
Here's an example that will plot different types of images, depending on
your answers to `query ' questions. The file called
`\filename' is the data file, in binary format with one byte
(`unsigned char ' in C) for each pixel, stored with the northwest
pixel first, and the pixel to the east of that next. The file called
`\mask ' is in the same format, and the numbers are 0 if the point
is over the sea and 1 if over land. The mask file is used in computing
the histograms, which is done if `\histo ' is 1.
The files in this example covers 128 * 128 pixels over the Gulf of
Maine. The numbers in `\filename ' correspond to surface
temperatures according to the equation
T = 5 + 0.1 * pixel_value
|
which explains the following lines in the command file:
\0val = "5" # 0 in image
\255val = "30.5" # 255 in image
|
Depending on `\histo ', the graymap will be linear or
histogram-enhanced. The histogram method
consists of dividing the cumulative histogram for the values in the
image up into 256 levels, and assigning a graylevel to each. This has
the effect of creating maximal contrast in all ranges of graylevel. It
points up features really well, but it's a nonlinear mapping, so it is
not good for telling you where gradients are strong or weak.
The command-file.
Click to see code
|