Importing and Exporting from Wavelet Analyzer App
The Wavelet Packet 1-D and Wavelet Packet 2-D tools let you import information from and export information to your disk.
If you adhere to the proper file formats, you can
Save decompositions as well as synthesized signals and images from the wavelet packet graphical tools to disk
Load signals, images, and 1-D and 2-D decompositions from disk into the Wavelet Packet 1-D and Wavelet Packet 2-D graphical tools
Saving Information to Disk
Using specific file formats, the graphical tools let you save synthesized signals or images, as well as 1-D or 2-D wavelet packet decomposition structures. This feature provides flexibility and allows you to combine command line and graphical interface operations.
Saving Synthesized Signals
You can process a signal in the Wavelet Packet 1-D tool, and then save the processed signal to a MAT-file.
For example, load the example analysis:
File > Example Analysis > db1 – depth: 2 – ent: shannon > sumsin
and perform a compression or denoising operation on the original signal. When you close the Wavelet Packet 1-D Denoising or Wavelet Packet 1-D Compression window, update the synthesized signal by clicking Yes in the dialog box.
Then, from the Wavelet Packet 1-D tool, select the File > Save > Synthesized Signal menu option.
A dialog box appears allowing you to select a folder and filename for the
MAT-file. For this example, choose the name synthsig.
To load the signal into your workspace, simply type
load synthsig whos
| Name | Size | Bytes | Class |
|---|---|---|---|
synthsig | 1x1000 | 8000 | double array |
valTHR | 1x1 | 8 | double array |
wname | 1x3 | 6 | char array |
The synthesized signal is given by synthsig. In addition,
the parameters of the denoising or compression process are given by the wavelet
name (wname) and the global threshold
(valTHR).
valTHR
valTHR =
1.9961
Saving Synthesized Images
You can process an image in the Wavelet Packet
2-D tool, and then save the processed image to a MAT-file (with
extension mat or other).
For example, load the example analysis:
File > Example Analysis > db1 – depth: 1 – ent: shannon > woman
and perform a compression on the original image. When you close the Wavelet Packet 2-D Compression window, update the synthesized image by clicking Yes in the dialog box that appears.
Then, from the Wavelet 2-D tool, select the File > Save > Synthesized Image menu option.
A dialog box appears allowing you to select a folder and filename for the
MAT-file. For this example, choose the name wpsymage.
To load the image into your workspace, simply type
load wpsymage whos
| Name | Size | Bytes | Class |
|---|---|---|---|
X | 256x256 | 524288 | double array |
map | 255x3 | 6120 | double array |
valTHR | 1x1 | 8 | double array |
wname | 1x3 | 6 | char array |
The synthesized image is given by X. The variable
map contains the associated colormap. In addition, the
parameters of the denoising or compression process are given by the wavelet name
(wname) and the global threshold
(valTHR).
Saving 1-D Decomposition Structures
The Wavelet Packet 1-D tool lets you save an
entire wavelet packet decomposition tree and related data to your disk. The
toolbox creates a MAT-file in the current folder with a name you choose,
followed by the extension wp1 (wavelet packet 1-D).
Open the Wavelet Packet 1-D tool and load the example analysis:
File > Example Analysis > db1 – depth: 2 – ent: shannon > sumsin
To save the data from this analysis, use the menu option File > Save Decomposition.
A dialog box appears that lets you specify a folder and file name for storing
the decomposition data. Type the name wpdecex1d.
After saving the decomposition data to the file
wpdecex1d.wp1, load the variables into your
workspace.
load wpdecex1d.wp1 -mat whos
| Name | Size | Bytes | Class |
|---|---|---|---|
data_name | 1x6 | 12 | char array |
tree_struct | 1x1 | 11176 | wptree object |
valTHR | 0x0 | 0 | double array |
The variable tree_struct contains the wavelet packet tree
structure. The variable data_name contains the data name and
valTHR contains the global threshold, which is currently
empty since the synthesized signal does not exist.
Saving 2-D Decomposition Structures
The file format, variables, and conventions are exactly the same as in the 1-D
case except for the extension, which is wp2 (wavelet packet
2-D). The variables saved are the same as with the 1-D case, with the addition
of the colormap matrix map:
| Name | Size | Bytes | Class |
|---|---|---|---|
data_name | 1x5 | 10 | char array |
map | 255x3 | 6120 | double array |
tree_struct | 1x1 | 527400 | wptree object |
valTHR | 1x1 | 8 | double array |
Save options are also available when performing denoising or compression inside the Wavelet Packet 1-D and Wavelet Packet 2-D tools.
In the Wavelet Packet Denoising windows, you can save the denoised signal or image and the decomposition. The same holds true for the Wavelet Packet Compression windows.
This way, you can save directly many different trials from inside the Denoising and Compression windows without going back to the main Wavelet Packet windows during a fine-tuning process.
Note
When saving a synthesized signal (1-D), a synthesized image (2-D) or a
decomposition to a MAT-file, the extension of this file is free. The
mat extension is not necessary.
Loading Information into the Graphical Tools
You can load signals, images, or 1-D and 2-D wavelet packet decompositions into the graphical interface tools. The information you load may have been previously exported from the graphical interface, and then manipulated in the workspace, or it may have been information you generated initially from the command line.
In either case, you must observe the strict file formats and data structures used by the graphical tools, or else errors will result when you try to load information.
Loading Signals
To load a signal you've constructed in your MATLAB® workspace into the Wavelet Packet
1-D tool, save the signal in a MAT-file (with extension
mat or other).
For instance, suppose you've designed a signal called warma
and want to analyze it in the Wavelet Packet
1-D tool.
save warma warma
The workspace variable warma must be a vector.
sizwarma = size(warma)
sizwarma =
1 1000
To load this signal into the Wavelet Packet 1-D tool, use the menu option File > Load Signal.
A dialog box appears that lets you select the appropriate MAT-file to be loaded.
Note
The first 1-D variable encountered in the file is considered the signal. Variables are inspected in alphabetical order.
Loading Images
This toolbox supports only indexed images. An indexed
image is a matrix containing only integers from 1 to n, where
n is the number of colors in the image.
This image may optionally be accompanied by a n-by-3 matrix
called map. This is the colormap associated with the image.
When MATLAB displays such an image, it uses the values of the matrix to look
up the desired color in this colormap. If the colormap is not given, the
Wavelet Packet 2-D graphical tool uses a
monotonic colormap with max(max(X))–min(min(X))+1
colors.
To load an image you've constructed in your MATLAB workspace into the Wavelet Packet
2-D tool, save the image (and optionally, the variable
map) in a MAT-file (with extension mat
or other).
For instance, suppose you've created an image called brain
and want to analyze it in the Wavelet Packet
2-D tool. Type
X = brain; map = pink(256); save myfile X map
To load this image into the Wavelet Packet 2-D tool, use the menu option File > Load Image.
A dialog box appears that lets you select the appropriate MAT-file to be loaded.
Note
The first 2-D variable encountered in the file (except the variable
map, which is reserved for the colormap) is
considered the image. Variables are inspected in alphabetical order.
Caution
The graphical tools allow you to load an image that does not contain
integers from 1 to n. The computations will be correct
since they act directly on the matrix, but the display of the image will be
strange. The values less than 1 will be evaluated as 1, the values greater
than n will be evaluated as n, and a
real value within the interval [1,n] will be evaluated as
the closest integer.
Note that the coefficients, approximations, and details produced by wavelet packets decomposition are not indexed image matrices. To display these images in a suitable way, the Wavelet Packet 2-D tool follows these rules:
Reconstructed approximations are displayed using the colormap
map. The same holds for the result of the reconstruction of selected nodes.The coefficients and the reconstructed details are displayed using the colormap
mapapplied to a rescaled version of the matrices.
Loading Wavelet Packet Decomposition Structures
You can load 1-D and 2-D wavelet packet decompositions into the graphical tools providing you have previously saved the decomposition data in a MAT-file of the appropriate format.
While it is possible to edit data originally created using the graphical tools and then exported, you must be careful about doing so. Wavelet packet data structures are complex, and the graphical tools do not do any consistency checking. This can lead to errors if you try to load improperly formatted data.
1-D data file contains the following variables:
| Variable | Status | Description |
|---|---|---|
tree_struct | Required | Object specifying the tree structure |
data_name | Optional | Character vector specifying the name of the decomposition |
valTHR | Optional | Global threshold (can be empty if neither compression nor denoising has been done) |
These variables must be saved in a MAT-file (with extension wp1
or other).
2-D data file contains the following variables:
| Variable | Status | Description |
|---|---|---|
tree_struct | Required | Object specifying the tree structure |
data_name | Optional | Character vector specifying the name of the decomposition |
map | Optional | Image map |
valTHR | Optional | Global threshold (can be empty if neither compression nor denoising has been done) |
These variables must be saved in a MAT-file (with extension
wp2 or other).
To load the properly formatted data, use the menu option File > Load Decomposition Structure from the appropriate tool, and then select the desired MAT-file from the dialog box that appears.
The Wavelet Packet 1-D or 2-D graphical tool then automatically updates its display to show the new analysis.
Note
When loading a signal (1-D), an image (2-D), or a decomposition (1-D or
2-D) from a MAT-file, the extension of this file is free. The
mat extension is not necessary.