3.2 Performing 2d Wavelet Transforms


3.2.1 Reading Data Files

To read a file of data into an Image window, select the Read Data File... item from the File menu. You will then see the following dialog:

The file type buttons can be set to read either normal data (i.e. 2d data values), sorted/truncated 2d wavelet coefficients (see section 4.2.7 on reading compressed data files), or raw images (1-byte/pixel gray-scale). The data type buttons can be set to read either text data (normal ASCII text delimited by tabs, commas, spaces, or returns) or binary data.

Text files must be of type 'TEXT', and must contain the following data:

      Number of rows in data:   ASCII value
      Number of cols in data:   ASCII value
      Each row of data:         ASCII values
Binary files must be of type 'WBIN'. Binary files can be created with Fortran, C, or other programs. The format for binary files is as follows:

      Number of rows in data:   4-byte integer value
      Number of cols in data:   4-byte integer value
      Each row of data:         4-byte real values
Binary files are much smaller than text, and read and write much faster.

Raw image files are simply a stream of (row-ordered) bytes (value 0-255) which represent the gray-scale value of each point in the image. Raw images can be produced with a C, Fortran, etc..., program, or by saving a gray-scale image in the "Raw" format from Photoshop. To read in a raw image, you must supply the number of X-points (cols) and Y-points (rows) in the image. Raw images are binary images.

After you have selected the file type and data type, click on OK. You will then be presented with a standard file dialog from which you can select the file to read. The data from this file will be displayed in the current window.


3.2.2 Performing a Discrete Wavelet Transform

The v2.00 MacWavelets program can perform periodic orthogonal discrete wavelet transforms and their inverses, from a variety of built-in or user-defined filter coefficients. The procedure for performing this transform is based on a multi-pass sparse-matrix multiplication by quadrature mirror filters, and includes input data wraparound at the far end of the forward transform, and at the near end of the inverse transform.

To perform a wavelet transform, first read (or create) data into an Image window. Then, select the Perform DWT item from the Wavelets menu. This item will display a submenu of wavelet filter choices:

Select one of the submenu choices (e.g. Daubechies 4) to perform a wavelet transform using that set of filter coefficients. A 2d DWT of a 256x256 image takes about 20-sec on my Centris 650.

In order to perform a transform, the x-length and y-length of your input data must be a power of 2. If your data is not a power of 2 in length, it will either be truncated to the next lowest power of 2 length, or padded to the next highest power of 2 length, depending on the Settings... item dialog in the Edit menu.

Once you have selected a filter type, the transform will be performed, and the result displayed in the current window, or in a new window, depending on the Settings... item dialog in the Edit menu. The discrete wavelet transform is a multi-step process. Each step is performed along the x-axis (cols) and then the y-axis (rows) of the input data. The total number of levels of analysis performed during this transform is also determined by the Settings... dialog.

Here is an example of the result of a wavelet transform:

Each resulting wavelet coefficient is displayed as one element of a 2-d array.


3.2.3 Using Custom Filters

You can also perform a transform using a custom set of filter coefficients. To use a custom filter, select the Custom... submenu item from the Perform DWT item of the Wavelets menu. You will then be prompted with a standard file dialog from which you can select a file of filter coefficients to use. This file must be in TEXT format, and contain the coefficients for the H and then the G quadrature mirror filters for the orthogonal transform you wish to perform. Each filter must have an even number of coefficients.


3.2.4 Performing an Inverse Discrete Wavelet Transform

To perform an inverse discrete wavelet transform, first select an Image window containing wavelet coefficients (i.e. the results of a forward wavelet transform). Then choose the Perform Inverse DWT item of the Wavelets menu, and select one of the filter sets from the submenu of this item. You can also use a custom set of filters to perform the inverse transform by choosing the Custom... item of the submenu. You will then be prompted for a TEXT file contaning your filter coefficients. A 2d inverse DWT of a 256x256 image takes about 20-sec on my Centris 650.


3.2.5 Generating Wavelets

You can see the shape of various wavelet functions by choosing the Generate Wavelet... item of the Wavelets menu, and then choosing a specific filter from the attached submenu. You can also generate a wavelet shape based on a custom filter by choosing the Custom... item of the submenu.

Once you have chosen a filter to use, you will see the following dialog:

Type in the number of X and Y points you would like in the resulting image, and the X-order and Y-order of the wavelet you wish to generate (from 1 to the number of X or Y points). The default for this order is the number of coefficients in the corresponding filter (e.g. 4 for the Daubechies 4 filter). The wavelet shape will be generated by creating an array which is equal to 1 at the (X-element, Y-element) numbers of the orders you entered, and which is zero everywhere else, and then performing an inverse wavelet transform on this array. Click on OK to generate the wavelet shape.

Here is an example of the wavelet shape for the Daubechies 4 filter, with an X-order and Y-order of 4:


3.2.6 Writing Data Files

To write a file of data from an Image window, choose the Write Data File... item from the File menu. You will then see the following dialog:

Select the Normal data-Sorted/truncated coeffs button to write a text or binary image or set of wavelet coefficients. Select the Raw image button to write a set of raw byte values (0-255) for each point in the image. The raw format does not contain any size information, and all data values will be rescaled to between 0 and 255. This format can be used for importing the image into Photoshop for further processing.

Select the Text button to write an ASCII file (comma and return delimited), or select the Binary button to write a binary file. The format of a text file is as follows:

      Number of rows in data:   ASCII value
      Number of cols in data:   ASCII value
      Each row of data:         ASCII values
The format of a binary file is as follows:

      Number of rows in data:   4-byte integer value
      Number of cols in data:   4-byte integer value
      Each row of data:         4-byte real values
A raw file is simply a stream of bytes, with no header.

Click on OK. You will then see a standard Macintosh file dialog from which you can name your data file. Text files are written as type 'TEXT', and binary files are written as type 'WBIN'. Binary files can be read by the MacWavelets program, or from Fortran, C, or other programs. Raw files can be read with C, Fortran, etc..., programs, or by Photoshop.


Contents | Previous Section | Next Section


MacWavelets 2.00 User's Manual.
"MacWavelets" is a trademark of Intergalactic Reality.
© Copyright Intergalactic Reality, 1996.
All rights reserved.

Photoshop is a trademark of Adobe, Inc.