Wavelets: Working with Images

This section provides additional information about working with images in the Wavelet Toolbox™ software. It describes the types of supported images and how the MATLAB® environment represents them, as well as techniques for analyzing color images.

Understanding Images in the MATLAB Environment

The basic data structure in MATLAB is the rectangular matrix, an ordered set of real or complex elements. This object is naturally suited to the representation of images, which are real-valued, ordered sets of color or intensity data. (This toolbox does not support complex-valued images.)

The word pixel is derived from picture element and usually denotes a single dot on a computer display, or a single element in an image matrix. You can select a single pixel from an image matrix using normal matrix subscripting. For example:

I(2,15)

returns the value of the pixel at row 2 and column 15 of the image I. By default, MATLAB scales images to fill the display axes; therefore, an image pixel may use more than a single pixel on the screen.

Indexed Images

A typical color image requires two matrices: a colormap and an image matrix. The colormap is an ordered set of values that represent the colors in the image. For each image pixel, the image matrix contains a corresponding index into the colormap. (The elements of the image matrix are floating-point integers, or flints, which MATLAB stores as double-precision values.)

The size of the colormap matrix is n-by-3 for an image containing n colors. Each row of the colormap matrix is a 1-by-3 red, green, blue (RGB) color vector

color = [R G B]

that specifies the intensity of the red, green, and blue components of that color. R, G, and B are real scalars that range from 0.0 (black) to 1.0 (full intensity). MATLAB translates these values into display intensities when you display an image and its colormap.

When MATLAB displays an indexed image, it uses the values in the image matrix to look up the desired color in the colormap. For instance, if the image matrix contains the value 18 in matrix location (86,198), the color for pixel (86,198) is the color from row 18 of the colormap.

Outside MATLAB, indexed images with n colors often contain values from 0 to n–1. These values are indices into a colormap with 0 as its first index. Since MATLAB matrices start with index 1, you must increment each value in the image, or shift up the image, to create an image that you can manipulate with toolbox functions.

Wavelet Decomposition of Indexed Images

Indexed images can be thought of as scaled intensity images, with matrix elements containing only integers from 1 to n, where n is the number of discrete shades in the image.

If the colormap is not provided, the graphical user interface tools display the image and processing results using a monotonic colormap with max(max(X))-min(min(X))+1 colors.

Since the image colormap is only used for display purposes, some indexed images may need to be preprocessed to achieve the correct results from the wavelet decomposition.

In general, color indexed images do not have linear, monotonic colormaps and need to be converted to the appropriate gray-scale indexed image before performing a wavelet decomposition.

How Decompositions Are Displayed

Note that the coefficients, approximations, and details produced by wavelet decomposition are not indexed image matrices.

To display these images in a suitable way, the graphical user interface tools follow these rules:

  • Reconstructed approximations are displayed using the colormap map.

  • The coefficients and the reconstructed details are displayed using the colormap map applied to a rescaled version of the matrices.

RGB (Truecolor) Images

An RGB image, sometimes referred to as a truecolor image, is stored in MATLAB as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. RGB images do not use a palette. The color of each pixel is determined by the combination of the red, green, and blue intensities stored in each color plane at the pixel's location. Graphics file formats store RGB images as 24-bit images, where the red, green, and blue components are 8 bits each. This yields a potential of 16 million colors.

The precision with which a real-life image can be replicated led to the nickname "truecolor image." An RGB MATLAB array can be of class double, single, uint8, or uint16. In an RGB array of class double, each color component is a value between 0 and 1.

The color components of an 8-bit RGB image are integers in the range [0, 255] rather than floating-point values in the range [0, 1].

Wavelet Decomposition of Truecolor Images

The truecolor images analyzed are m-by-n-by-3 arrays of uint8. Each of the three-color components is a matrix that is decomposed using the two-dimensional wavelet decomposition scheme.

Other Images

Wavelet Toolbox software lets you work with some other types of images. Using the imread function, the various tools using images try to load indexed images from files that are not MAT files (for example, PCX files).

These tools are:

  • Two-Dimensional Discrete Wavelet Analysis

  • Two-Dimensional Wavelet Packet Analysis

  • Two-Dimensional Stationary Wavelet Analysis

  • Two-Dimensional Extension tool

For more information on the supported file types, type help imread.

Use the imfinfo function to find the type of image stored in the file. If the file does not contain an indexed image, the load operation fails.

Image Conversion

Image Processing Toolbox™ software provides a comprehensive set of functions that let you easily convert between image types. If you do not have Image Processing Toolbox software, the examples below demonstrate how this conversion may be performed using basic MATLAB commands.

Example 1: Converting Color Indexed Images

load xpmndrll 
whos 
NameSizeBytesClass
X2192x200307200double array
map64x31536double array

image(X2)
title('Original Color Indexed Image') 
colormap(map); colorbar

The color bar to the right of the image is not smooth and does not monotonically progress from dark to light. This type of indexed image is not suitable for direct wavelet decomposition with the toolbox and needs to be preprocessed.

First, separate the color indexed image into its RGB components:

R = map(X2,1); R = reshape(R,size(X2));
G = map(X2,2); G = reshape(G,size(X2));
B = map(X2,3); B = reshape(B,size(X2));

Next, convert the RGB matrices into a gray-scale intensity image, using the standard perceptual weightings for the three-color components:

Xrgb = 0.2990*R + 0.5870*G + 0.1140*B;

Then, convert the gray-scale intensity image back to a gray-scale indexed image with 64 distinct levels and create a new colormap with 64 levels of gray:

n = 64;            % Number of shades in new indexed image 
X = round(Xrgb*(n-1)) + 1; 
map2 = gray(n); 
figure 
image(X), title('Processed
Gray Scale Indexed Image') 
colormap(map2), colorbar

The color bar of the converted image is now linear and has a smooth transition from dark to light. The image is now suitable for wavelet decomposition.

Finally, save the converted image in a form compatible with the Wavelet Toolbox graphical user interface:

baboon = X; 
map = map2; 
save baboon baboon map

Example 2: Converting an RGB TIF Image

Suppose the file myImage.tif contains an RGB image (noncompressed) of size S1xS2. Use the following commands to convert this image:

A = imread('myImage.tif');  
% A is an S1xS2x3 array of uint8.  

A = double(A);
Xrgb  = 0.2990*A(:,:,1) + 0.5870*A(:,:,2) + 0.1140*A(:,:,3); 
NbColors = 255; 
X = wcodemat(Xrgb,NbColors); 
map = pink(NbColors);

The same program can be used to convert BMP or JPEG files.

Was this topic helpful?