wavelet.c File Reference

This is a standard wavelet library that takes a given data buffer of some data type and then performs a wavelet transform on that data. More...

#include "common.h"
#include <stdio.h>
#include <string.h>
#include "bu.h"
#include "vmath.h"
#include "bn.h"
Include dependency graph for wavelet.c:

Go to the source code of this file.

Defines

#define decompose_1d(DATATYPE)   bn_wlt_haar_1d_ ## DATATYPE ## _decompose
#define make_wlt_haar_1d_decompose(DATATYPE)
#define reconstruct(DATATYPE)   bn_wlt_haar_1d_ ## DATATYPE ## _reconstruct
#define make_wlt_haar_1d_reconstruct(DATATYPE)
#define decompose_2d(DATATYPE)   bn_wlt_haar_2d_ ## DATATYPE ## _decompose
#define make_wlt_haar_2d_decompose(DATATYPE)
#define reconstruct_2d(DATATYPE)   bn_wlt_haar_2d_ ## DATATYPE ## _reconstruct
#define make_wlt_haar_2d_reconstruct(DATATYPE)
#define decompose_2d_2(DATATYPE)   bn_wlt_haar_2d_ ## DATATYPE ## _decompose2
#define make_wlt_haar_2d_decompose2(DATATYPE)

Detailed Description

This is a standard wavelet library that takes a given data buffer of some data type and then performs a wavelet transform on that data.

The transform operations available are to either decompose or reconstruct a signal into its corresponding wavelet form based on the haar wavelet.

Wavelet decompose/reconstruct operations

For greatest accuracy, it is preferable to convert everything to "double" and decompose/reconstruct with that. However, there are useful properties to performing the decomposition and/or reconstruction in various data types (most notably char).

Rather than define all of these routines explicitly, we define 2 macros "decompose" and "reconstruct" which embody the structure of the function (which is common to all of them). We then instatiate these macros once for each of the data types. It's ugly, but it assures that a change to the structure of one operation type (decompose or reconstruct) occurs for all data types.

bn_wlt_haar_1d_*_decompose(tbuffer, buffer, dimen, channels, limit)

Parameters:
  • tbuffer a temporary data buffer 1/2 as large as "buffer". See (1) below.
  • buffer pointer to the data to be decomposed
  • dimen the number of samples in the data buffer
  • channels the number of values per sample
  • limit the extent of the decomposition

Perform a Haar wavelet decomposition on the data in buffer "buffer". The decomposition is done "in place" on the data, hence the values in "buffer" are not preserved, but rather replaced by their decomposition. The number of original samples in the buffer (parameter "dimen") and the decomposition limit ("limit") must both be a power of 2 (e.g. 512, 1024). The buffer is decomposed into "average" and "detail" halves until the size of the "average" portion reaches "limit". Simultaneous decomposition of multi-plane (e.g. pixel) data, can be performed by indicating the number of planes in the "channels" parameter.

(1) The process requires a temporary buffer which is 1/2 the size of the longest span to be decomposed. If the "tbuffer" argument is non-null then it is a pointer to a temporary buffer. If the pointer is NULL, then a local temporary buffer will be allocated (and freed).

Examples:
 double dbuffer[512], cbuffer[256];
 ...
 bn_wlt_haar_1d_double_decompose(cbuffer, dbuffer, 512, 1, 1);

performs complete decomposition on the data in array "dbuffer".

 double buffer[3][512];  /_* 512 samples, 3 values/sample (e.g. RGB?)*_/
 double tbuffer[3][256];         /_* the temporary buffer *_/
 ...
 bn_wlt_haar_1d_double_decompose(tbuffer, buffer, 512, 3, 1);

This will completely decompose the data in buffer. The first sample will be the average of all the samples. Alternatively:

bn_wlt_haar_1d_double_decompose(tbuffer, buffer, 512, 3, 64);

decomposes buffer into a 64-sample "average image" and 3 "detail" sets.

bn_wlt_haar_1d_*_reconstruct(tbuffer, buffer, dimen, channels, sub_sz, limit)

Definition in file wavelet.c.


Define Documentation

#define decompose_1d ( DATATYPE   )     bn_wlt_haar_1d_ ## DATATYPE ## _decompose

This source file uses C-styple "templates" where functions specific to a set of specified data types are automatically declared/provided via one single macro implementation.

Definition at line 157 of file wavelet.c.

#define make_wlt_haar_1d_decompose ( DATATYPE   ) 

DATATYPE *tbuffer; // temporary buffer DATATYPE *buffer; // data buffer unsigned long dimen; // # of samples in data buffer unsigned long channels; // # of data values per sample unsigned long limit; // extent of decomposition

Definition at line 168 of file wavelet.c.

#define reconstruct ( DATATYPE   )     bn_wlt_haar_1d_ ## DATATYPE ## _reconstruct

Definition at line 218 of file wavelet.c.

#define make_wlt_haar_1d_reconstruct ( DATATYPE   ) 

Definition at line 220 of file wavelet.c.

#define decompose_2d ( DATATYPE   )     bn_wlt_haar_2d_ ## DATATYPE ## _decompose
#define make_wlt_haar_2d_decompose ( DATATYPE   ) 
#define reconstruct_2d ( DATATYPE   )     bn_wlt_haar_2d_ ## DATATYPE ## _reconstruct
#define make_wlt_haar_2d_reconstruct ( DATATYPE   ) 
#define decompose_2d_2 ( DATATYPE   )     bn_wlt_haar_2d_ ## DATATYPE ## _decompose2
#define make_wlt_haar_2d_decompose2 ( DATATYPE   ) 
Generated on Tue Dec 11 13:14:28 2012 for LIBBN by  doxygen 1.6.3