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.
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.
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.
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 Wavelet Analyzer app displays 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.
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 Wavelet Analyzer app follows 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.
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].
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 2-D wavelet decomposition scheme.
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:
2-D Discrete Wavelet Analysis
2-D Wavelet Packet Analysis
2-D Stationary Wavelet Analysis
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 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.
load xpmndrll whos
Name | Size | Bytes | Class |
---|---|---|---|
X2 | 192x200 | 307200 | double array |
map | 64x3 | 1536 | double 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 Wavelet Analyzer app:
baboon = X; map = map2; save baboon baboon map
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.