Wavelet Toolbox |
Image Conversion
The Image Processing Toolbox provides a comprehensive set of functions that let you easily convert between image types. Should you not have the Image Processing Toolbox, the examples below demonstrate how this conversion may be performed using basic MATLAB commands.
Example 1 - Converting Color Indexed Images
load xpmndrll whos
Name |
Size |
Bytes |
Class |
X2 |
192x200 |
307200 |
double array |
map |
64x3 |
1536 |
double array |
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 we 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 we convert the RGB matrices into a gray-scale intensity image, using the standard perceptual weightings for the three-color components,
Then, we 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, we save the converted image in a form compatible with the Wavelet Toolbox graphical user interface,
Example 2 - Converting an RGB tif-Image.
Suppose the file myImage.tif
contains an RGB image (noncompressed) of size S1xS2
, you can use the following basic MATLAB 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.
Other Images | One-Dimensional Discrete Stationary Wavelet Analysis |
© 1994-2005 The MathWorks, Inc.