4.2 Performing 2d Compression/Expansion


4.2.1 Sorting Coefficients

To sort a set of wavelet coefficients, first select an Image window containing the results of a wavelet transform. Then, choose the Sort Coeffs item from the Wavelets menu. Your coefficients will then be sorted in order of decreasing absolute magnitude. Sorting a 256x256 image takes about 20-sec on a Centris 650.

Here is an example of a set of sorted coefficients:

Notice the glyph along the bottom of the sorted Image window. This glyph tells you that the data in this window has been sorted (and can therefore be unsorted).


4.2.2 Truncating Coefficients

To truncate a set of sorted wavelet coefficients, choose the Truncate Coeffs... item from the Wavelets menu. You will then see the following dialog:

Truncating coefficients means throwing some of them away (i.e. setting their values to zero, and then resizing the array to eliminate them). The Truncate Coeffs... dialog allows you to truncate wavelet coefficients in 4 ways:

  1. Keep a number of coefficients. Select this item and fill in the number of coefficients to keep. The truncation operation will then keep those N coefficients with the largest absolute values, for whatever N you entered.
  2. Keep a percentage of coefficients. Select this item and fill in the percent of coefficients to keep. The truncation operation will then keep those N% coefficients with the largest absolute values, for whatever N% you entered.
  3. Keep all coefficients greater than or equal to some value. Select this item and fill in the smallest coefficient value you want to keep. The truncation operation will then keep only those coefficients with absolute values greater than or equal to the value you entered.
  4. Keep all coefficients greater than or equal to some percentage of the largest coefficient value. Select this item and fill in the smallest percentage value you want to keep. The truncation operation will then keep only those coefficients with absolute values greater than or equal to that percentage of the maximum coefficient value.

Here is an example of a truncation operation which kept 50% of the previous set of coefficients:

Note that the resulting truncated coefficients are formatted into the smallest square which will contain them. This is purely for display purposes only, and will have no effect on further operations. If the truncated data is written to a file (see section 4.2.8 below), or is used to reconstruct data, only the actual retained coefficients will be used, and any "padding" will be discarded.


4.2.3 Unsorting Coefficients

To unsort a set of sorted or truncated coefficients, first select the Image window containing the coefficients. Then, choose the Unsort Coeffs item from the Wavelets menu. The coefficients will then be unsorted back into their original order within the coefficient array, and the image will be expanded to its original size.

Notice that when data is unsorted:

Once the coefficient array has been unsorted, it can be used in an inverse wavelet transform to reconstruct the original dataset.


4.2.4 Compressing Data

Two of the three previous processes (sorting, truncation), as well as performing an initial discrete wavelet transform, can be combined into a single step with the Compress... item of the Wavelets menu.

Choosing this item will perform the following steps in sequence:

  1. Present the Truncate Coeffs... dialog.
  2. Perform a discrete wavelet transform on the input dataset using a filter set you select.
  3. Sort the resulting wavelet coefficients.
  4. Truncate the sorted coefficients based on the Truncate Coeffs... dialog settings.

To perform a compression, first select an Image window containing 2d data. Then, choose the Compress... item of the Wavelets menu, and one of the filter items of the attached submenu. Whatever filter set you choose from the submenu will be used to perform the wavelet transform as part of the compression operation. You can also perform compression using a custom filter by choosing the Custom... item of the submenu. Compression of a 256x256 image takes about 40-sec on a Centris 650.

Here is an example of an input dataset and its compressed coefficients, based on keeping 50% of the sorted coefficients (i.e 2:1 compression):


4.2.5 Expanding Data

The Expand... item of the Wavelets menu will perform the following steps in sequence:

  1. Unsort (and restore to original length) a set of truncated wavelet coefficients.
  2. Perform an inverse wavelet transform of the unsorted coefficients using the filter set you select.

To perform an expansion, first select a Wavelet window containing truncated wavelet coefficients. Then, choose the Expand... item of the Wavelets menu, and one of the filter items of the attached submenu. Whatever filter set you choose from the submenu will be used to perform the inverse wavelet transform as part of the expansion operation. You can also perform expansion using a custom filter by choosing the Custom... item of the submenu. Expansion of a 256x256 image takes about 40-sec on a Centris 650.

Here is an example of an expansion of the previously compressed dataset:

Note that this dataset appears very similar to the original dataset, even though 50% of the intermediate wavelet coefficients were eliminated.


4.2.6 Comparing Reconstructed Data

Wavelet compression ratios of much greater than 2x can be achieved by using an appropriate set of wavelet filter coefficients for a given dataset. Usually, selecting a longer filter will also improve compression. Here is an example of performing the previous compression and expansion with the Daubechies 20 set of filter coefficients, keeping only 10% of the intermediate wavelet coefficients (i.e. a compression ratio of 10x):

To compare the reconstructed data to the original, you can subtract the original dataset from the reconstructed one. To do this, first select the window containing the reconstructed dataset. Then, choose the Subtract Datasets... item from the Wavelets menu. You will see the following dialog:

From the pop-up menu of windows (every 2d window in the current document), choose the Original window. When performing subtraction and other math operations, you may want to name your windows first, so that you can distinguish one from another in the pop-up menu. The result of subtracting the original dataset from the reconstruction looks like the following:

Note that the magnitude of the difference is at most about 10% of the original.

One way to measure the accuracy of reconstruction of the data is to look at the average sum of squared differences between the original and the reconstruction. This information is available from the Data Stats... item of the Edit menu. To see this infomation, select the window showing the subtracted dataset, and then choose the Data Stats... menu item. You should see the following:

When compressing data, you may want to try different wavelet filter sets and different truncation options, until you find the method that eliminates the most coefficients, while minimizing the average sum of squares difference between the original data and its reconstruction.


4.2.7 Reading Compressed Data Files

To read a previously saved set of sorted or truncated coefficients into an Image window, choose the Read Data File... item from the File menu. In the following dialog, select the Sorted/truncated coeffs button:

You may select either the Text or Binary Data type: button. The format of a text file of sorted/truncated coefficients is the following:

      Original number of rows, cols in data:   Text value, text value
      Actual number of points:                 Text value
      Current rows, cols of array 
      (including padding):                     Text value, text value
      Each row of data:                        Text values
      Each row of index of data:               Text values
The original number of rows and cols is the size of the unsorted array. The index of each point is the position (0-based) that the point occupied in the unsorted array, considered as a single row vector.

Note that not all current rows and columns of data or index may be written to the file, due to display padding. Only as many values as the current number of actual truncated values will be written. Therefore, some rows, and some columns within the last row, of padded data may be omitted from the file.

The format of a binary file of sorted/truncated coefficients is the following:

      Original number of rows in data:   4-byte integer value
      Original number of cols in data:   4-byte integer value
      Actual number of points:           4-byte integer value
      Current number of rows in data:    4-byte integer value
      Current number of cols in data:    4-byte integer value
      Each data point:                   4-byte real value
      Index of each data point:          4-byte integer value
Again, note that not all values or indices may be written to the file, due to display padding. Only as many values as the current number of actual truncated values will be written.


4.2.8 Writing Compressed Data Files

To write a file of sorted or truncated coefficients, simply choose the Write Data File... item from the File menu, and then select the Normal data-Sorted/truncated coeffs button, and either the Text or Binary data type from the dialog which follows.

Note that only the actual number of current truncated points and their indices will be written to the file, in one of the formats listed above.


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.