Digital Images: File Formats, Serialization, and Data Structures - Prof. Stephen Reichenba, Study notes of Digital Signal Processing

An overview of digital images, discussing various file formats, serialization methods, and data structures such as the java bufferedimage class. It covers grayscale and binary images, color images, raster order, pixel interleaving, and band interleaving. The document also touches upon multi-band, time-sequence, and volume images, as well as metadata.

Typology: Study notes

Pre 2010

Uploaded on 08/26/2009

koofers-user-qcm-2
koofers-user-qcm-2 🇺🇸

10 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Digital Images
Many different file formats and data structures have been devised to represent digital images.
The large variety is due in part to varying needs for different types of images and for different
applications, but the variety also reflects a common practice of organizations developing their
own solutions despite the availability of existing solutions.
1.1 Structure Issues
1.1.1 Pixel Data Type
For each pixel value that is a quantitative measurement of the irradiance on the camera focal
plane, a digital number (DN) must be stored in the computer. Most computer languages
offer several data types for numeric values, including integers and floating-point data-types of
various lengths. Most image acquisition devices convert the analog signals to integer values
because integers are simpler to represent and manipulate than floating-point values.
A simple type of digital image uses one 8-bit, unsigned integer to represent each value. Eight-
bit, unsigned integers have a range of 0 255 (28values). Negative numbers aren’t required
for irradiance measures because incident light is non-negative. Typically, zero is used to
represent no irradiance and 255 is used to represent the maximum irradiance. This scale
is called a grayscale because there is no color data and each value on the scale is called
agraylevel. Such images are called grayscale (or graylevel) or achromatic (i.e.without
color) images. Eight bits is a satisfactory length on two counts. First, it is the shortest
data-type and the shortest integer available in most computer languages, so it is the built-in
format with the least storage overhead. Second, the intensity resolution exceeds that which
can be distinguished visually, because the human eye can distinguish fewer than 256 levels
of gray. So, 8-bit pixel values are a good compromise of cost and performance for displayed,
grayscale images.
An even simpler type of digital image, a binary image, uses 1-bit for each value. Typi-
cally, one value is for black and one value is for white. Most computers have byte-oriented
storage, so binary images typically must be stored with one bit per byte, which facilitates
fast and simple easy access, or packed with 8 pixels per byte. Binary images are useful for
representing scanned documents with simple black-on-white printing.
For color images, it is common to use three 8-bit, unsigned integers one each for irradi-
ance in the red, green, and blue wavelengths. This provides a palette of 16,777,216 different
colors (224 values). This exceeds the number of distinct colors that the human eye can
distinguish. (It also exceeds the number of pixels on most display monitors.)
For highly quantitative applications, 8-bit measures may not provide adequate precision. In
such systems, 16-bit or 32-bit (signed or unsigned) integers often are used to represent pixel
values because they correspond to the built-in data types of popular programming languages.
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Digital Images: File Formats, Serialization, and Data Structures - Prof. Stephen Reichenba and more Study notes Digital Signal Processing in PDF only on Docsity!

Digital Images

Many different file formats and data structures have been devised to represent digital images. The large variety is due in part to varying needs for different types of images and for different applications, but the variety also reflects a common practice of organizations developing their own solutions despite the availability of existing solutions.

1.1 Structure Issues

1.1.1 Pixel Data Type

For each pixel value that is a quantitative measurement of the irradiance on the camera focal plane, a digital number (DN) must be stored in the computer. Most computer languages offer several data types for numeric values, including integers and floating-point data-types of various lengths. Most image acquisition devices convert the analog signals to integer values because integers are simpler to represent and manipulate than floating-point values.

A simple type of digital image uses one 8-bit, unsigned integer to represent each value. Eight- bit, unsigned integers have a range of 0 – 255 (2^8 values). Negative numbers aren’t required for irradiance measures because incident light is non-negative. Typically, zero is used to represent no irradiance and 255 is used to represent the maximum irradiance. This scale is called a grayscale because there is no color data and each value on the scale is called a graylevel. Such images are called grayscale (or graylevel) or achromatic (i.e.without color) images. Eight bits is a satisfactory length on two counts. First, it is the shortest data-type and the shortest integer available in most computer languages, so it is the built-in format with the least storage overhead. Second, the intensity resolution exceeds that which can be distinguished visually, because the human eye can distinguish fewer than 256 levels of gray. So, 8-bit pixel values are a good compromise of cost and performance for displayed, grayscale images.

An even simpler type of digital image, a binary image, uses 1-bit for each value. Typi- cally, one value is for black and one value is for white. Most computers have byte-oriented storage, so binary images typically must be stored with one bit per byte, which facilitates fast and simple easy access, or packed with 8 pixels per byte. Binary images are useful for representing scanned documents with simple black-on-white printing.

For color images, it is common to use three 8-bit, unsigned integers — one each for irradi- ance in the red, green, and blue wavelengths. This provides a palette of 16,777,216 different colors (2^2 4 values). This exceeds the number of distinct colors that the human eye can distinguish. (It also exceeds the number of pixels on most display monitors.)

For highly quantitative applications, 8-bit measures may not provide adequate precision. In such systems, 16-bit or 32-bit (signed or unsigned) integers often are used to represent pixel values because they correspond to the built-in data types of popular programming languages.

In computer processing that performs arithmetic operations, it is frequently desirable to use floating-point numbers (either single precision or double precision).

Support for different pixel data types is one factor that has led to the development of multiple file formats. Applications requiring only 8-bit values can use a simple file format that supports only 8-bit pixel values, but such a simple format cannot be used for applications that require greater precision or a greater variety of data types. Some file formats have used ASCII character data to represent pixel values in order to avoid machine specific issues such as byte-order in multi-byte data types. This approach is simple and easily portable, but requires more data storage and additional computation for encoding and decoding.

1.1.2 Serialization

One of the issues in file and data formats is the need to represent image data in a sequential manner. For example, image data must be sequenced to be communicated over a wire or mapped into the sequential memory of a computer. The conversion of data to a sequence is called serialization or marshalling.

A simple type of digital image is a rectangular, two-dimensional array of pixels with a single value for each pixel. The typical ordering of an image is the order that they are displayed in standard display monitors — left-to-right (as viewed) across the first line and the left-to- right across each subsequent line — as pictured in Figure 1. This is called raster order (after raster display devices) or row-major order.

Color images typically have three values for each pixel, so serialization is somewhat more complicated. The two most common approaches for serializing color images are:

  • pixel interleaving and
  • band interleaving.

Both schemes typically use raster order, but differ on how the three color bands are handled. For pixel interleaving, all three values for each pixel are stored together — the three values for the first pixel are followed by the three values for the second pixel and so on, with pixels in raster order. For band interleaving, the color image is stored as three bands with each band in raster order, e.g., the raster of all red values would be followed by the raster of all green values, followed by the raster of all blue values.

Figure 1: Raster order.

  1. Width — an ASCII decimal number.
  2. Height — an ASCII decimal number.
  3. Image — a raster-order sequence of Width×Height ASCII characters equal to ‘0’ or ‘1’ with ‘1’ for black and ‘0’ for white.

The fields of the format are separated by whitespace (one or more blank, tab, carriage-return, or linefeed characters). Whitespace in the image field is ignored. Characters from a ‘#’ to the next end-of-line are ignored (which allows comments). No line should be longer than 70 characters.

Here is a small, example PBM file:

P

Width and Height

4 2

Image

1 1 0 1 0 0 1 1

End of file

There is also a PBM RAWBITS format with a magic number of “P4” and with the pixel values represented by binary numbers with bits packed in bytes. The PGM format is very similar, but has a magic number of “P2” (or “P5” for RAWBITS), an extra field after Width and Height which specifies the maximum pixel value, and pixel values that are ASCII formatted (or binary, 8-bit unsigned) integers. The PNM format is similar to PGM, but has a magic number of “P3” (or “P6” for RAWBITS) and three values for each pixel with pixel interleaving.

Here is an example PNM file:

P

Maximum value

255 255 255 255 255 255 128 255 128 128 128 128 128 100 100 100 101 102 104 102 104 108 104 108 116

1.3 Example Data Structure: Java BufferedImage Class

The Java BufferedImage class is an objected-oriented programming language construct for digital images. The BufferedImage class is provided in the Java Abstract Windowing Toolkit

(AWT) as a part of the Java 2D Application Programmer Interface (API). Java offers addi- tional support digital images in the Java Advanced Imaging (JAI) package. The Buffered- Image class implements the RenderedImage interface, which is the Java 2D interface for objects that contain or can produce raster images. The Java programming language also provides several other constructs for digital images, some of which support more abstract handling than the BufferedImage class, but the BufferedImage class is particularly attractive for introductory purposes because it has an accessible buffer with image data that can be operated on directly. For documentation on Java2D imaging, see:

http://java.sun.com/j2se/1.4/docs/api/java/awt/image/package-summary.html

and for documentation on JAI, see:

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/index.html

The BufferedImage class is comprised of two constructs — a raster and a color model — and several associated methods. The Raster is a rectangular array of pixels and the ColorModel encapsulates the methods for mapping the pixel values to colors. The Raster is comprised of two constructs — a data buffer and a sample model. The DataBuffer stores the pixel values and the SampleModel encapsulates the methods to locate pixel values in the DataBuffer. Figure ?? illustrates composition of the BufferedImage class.

A DataBuffer object contains one or more data arrays holding pixel values. Each pixel may have one or more samples. For example, a color image may have three values per pixel (for red, green, and blue). Such a color image would have three bands: one band of red samples, one band of green samples, and one band of blue samples. In the BufferedImage vocabulary, the primitive data type of the samples is the transfer type. The transfer type of a Buffered- Image object’s ColorModel, DataBuffer, and Sample Model, must match. The supported data types for the DataBuffer class are TYPE BYTE, TYPE SHORT, TYPE USHORT, TYPE INT, TYPE DOUBLE, and TYPE FLOAT.

The SampleModel class supports various schemes of organizing the samples, including the BandedSampleModel subclass for band interleaving and the PixelInterleavedSampleModel subclass for pixel interleaving. The SampleModel class also supports schemes that pack samples in larger data elements for storage efficiency.

The Raster class generalizes the simple coordinate system used by the SampleModel class. The SampleModel class uses a coordinate system that starts with (0,0), but the RasterClass allows translation to any position. The Raster class also supports child rasters (including sub- image children and translated children). The WriteableRaster subclass extends the Raster class to allow writing to pixel values.

A simple constructor for the BufferedImage class has parameters for width, height, and image type, where image type can specify one of 13 standard pairings (or one custom pairing) of SampleModel and ColorModel.

System.out.println("ColorSpace MaxValue:"

  • img.getColorModel().getColorSpace().getMaxValue(0)); System.out.println("Raster TransferType:"
  • img.getRaster().getTransferType()); System.out.println("SampleModel NumBands:"
  • img.getRaster().getSampleModel().getNumBands()); for (int x=0; x<128; x++) { for (int y=0; y<128; y++) { ras.setSample(x, y, 0, (x+y)%256); }} JLabel view = new JLabel(new ImageIcon(img)); getContentPane().add(view); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } }); }

public static void main(String[] argv) { try { JFrame frame = new DemoDisplay(); frame.pack(); frame.setVisible(true); } catch (Exception e) { System.err.println(e); System.exit(1); } }

Visit the following class descriptions at the Java AWT documentation WWW site:

http://java.sun.com/j2se/1.4/docs/api/java/awt/

image/BufferedImage.html image/Raster.html image/WritableRaster.html image/DataBuffer.html image/DataBufferByte.html image/DataBufferShort.html image/DataBufferUShort.html

image/DataBufferInt.html image/DataBufferFloat.html image/DataBufferDouble.html image/SampleModel.html image/ComponentSampleModel.html image/BandedSampleModel.html image/PixelInterleavedSampleModel.html image/ColorModel.html image/ComponentColorModel.html image/IndexColorModel.html color/ColorSpace.html