BRL-CAD
wavelet.h
Go to the documentation of this file.
1 /* W A V E L E T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /*----------------------------------------------------------------------*/
22 /* @file wavelet.h */
23 /** @addtogroup wavelet */
24 /** @{ */
25 
26 /** @brief
27  * This is a standard wavelet library that takes a given data buffer of some data
28  * type and then performs a wavelet transform on that data.
29  *
30  * The transform
31  * operations available are to either decompose or reconstruct a signal into its
32  * corresponding wavelet form based on the haar wavelet.
33  *
34  * Wavelet decompose/reconstruct operations
35  *
36  * - bn_wlt_haar_1d_double_decompose(tbuffer, buffer, dimen, channels, limit)
37  * - bn_wlt_haar_1d_float_decompose (tbuffer, buffer, dimen, channels, limit)
38  * - bn_wlt_haar_1d_char_decompose (tbuffer, buffer, dimen, channels, limit)
39  * - bn_wlt_haar_1d_short_decompose (tbuffer, buffer, dimen, channels, limit)
40  * - bn_wlt_haar_1d_int_decompose (tbuffer, buffer, dimen, channels, limit)
41  * - bn_wlt_haar_1d_long_decompose (tbuffer, buffer, dimen, channels, limit)
42  *
43  * - bn_wlt_haar_1d_double_reconstruct(tbuffer, buffer, dimen, channels, sub_sz, limit)
44  * - bn_wlt_haar_1d_float_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
45  * - bn_wlt_haar_1d_char_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
46  * - bn_wlt_haar_1d_short_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
47  * - bn_wlt_haar_1d_int_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
48  * - bn_wlt_haar_1d_long_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
49  *
50  * - bn_wlt_haar_2d_double_decompose(tbuffer, buffer, dimen, channels, limit)
51  * - bn_wlt_haar_2d_float_decompose (tbuffer, buffer, dimen, channels, limit)
52  * - bn_wlt_haar_2d_char_decompose (tbuffer, buffer, dimen, channels, limit)
53  * - bn_wlt_haar_2d_short_decompose (tbuffer, buffer, dimen, channels, limit)
54  * - bn_wlt_haar_2d_int_decompose (tbuffer, buffer, dimen, channels, limit)
55  * - bn_wlt_haar_2d_long_decompose (tbuffer, buffer, dimen, channels, limit)
56  *
57  * - bn_wlt_haar_2d_double_reconstruct(tbuffer, buffer, dimen, channels, sub_sz, limit)
58  * - bn_wlt_haar_2d_float_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
59  * - bn_wlt_haar_2d_char_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
60  * - bn_wlt_haar_2d_short_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
61  * - bn_wlt_haar_2d_int_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
62  * - bn_wlt_haar_2d_long_reconstruct (tbuffer, buffer, dimen, channels, sub_sz, limit)
63  *
64  * - bn_wlt_haar_2d_double_decompose2(tbuffer, buffer, width, height, channels, limit)
65  * - bn_wlt_haar_2d_float_decompose2 (tbuffer, buffer, width, height, channels, limit)
66  * - bn_wlt_haar_2d_char_decompose2 (tbuffer, buffer, width, height, channels, limit)
67  * - bn_wlt_haar_2d_short_decompose2 (tbuffer, buffer, width, height, channels, limit)
68  * - bn_wlt_haar_2d_int_decompose2 (tbuffer, buffer, width, height, channels, limit)
69  * - bn_wlt_haar_2d_long_decompose2 (tbuffer, buffer, width, height, channels, limit)
70  *
71  * - bn_wlt_haar_2d_double_reconstruct2(tbuffer, buffer, width, height, channels, sub_sz, limit)
72  * - bn_wlt_haar_2d_float_reconstruct2 (tbuffer, buffer, width, height, channels, sub_sz, limit)
73  * - bn_wlt_haar_2d_char_reconstruct2 (tbuffer, buffer, width, height, channels, sub_sz, limit)
74  * - bn_wlt_haar_2d_short_reconstruct2 (tbuffer, buffer, width, height, channels, sub_sz, limit)
75  * - bn_wlt_haar_2d_int_reconstruct2 (tbuffer, buffer, width, height, channels, sub_sz, limit)
76  * - bn_wlt_haar_2d_long_reconstruct2 (tbuffer, buffer, width, height, channels, sub_sz, limit)
77  *
78  *
79  * For greatest accuracy, it is preferable to convert everything to "double"
80  * and decompose/reconstruct with that. However, there are useful
81  * properties to performing the decomposition and/or reconstruction in
82  * various data types (most notably char).
83  *
84  * Rather than define all of these routines explicitly, we define
85  * 2 macros "decompose" and "reconstruct" which embody the structure of
86  * the function (which is common to all of them). We then instantiate
87  * these macros once for each of the data types. It's ugly, but it
88  * assures that a change to the structure of one operation type
89  * (decompose or reconstruct) occurs for all data types.
90  *
91  *
92  *
93  *
94  * bn_wlt_haar_1d_*_decompose(tbuffer, buffer, dimen, channels, limit)
95  * @par Parameters:
96  * - tbuffer a temporary data buffer 1/2 as large as "buffer". See (1) below.
97  * - buffer pointer to the data to be decomposed
98  * - dimen the number of samples in the data buffer
99  * - channels the number of values per sample
100  * - limit the extent of the decomposition
101  *
102  * Perform a Haar wavelet decomposition on the data in buffer "buffer". The
103  * decomposition is done "in place" on the data, hence the values in "buffer"
104  * are not preserved, but rather replaced by their decomposition.
105  * The number of original samples in the buffer (parameter "dimen") and the
106  * decomposition limit ("limit") must both be a power of 2 (e.g. 512, 1024).
107  * The buffer is decomposed into "average" and "detail" halves until the
108  * size of the "average" portion reaches "limit". Simultaneous
109  * decomposition of multi-plane (e.g. pixel) data, can be performed by
110  * indicating the number of planes in the "channels" parameter.
111  *
112  * (1) The process requires a temporary buffer which is 1/2 the size of the
113  * longest span to be decomposed. If the "tbuffer" argument is non-null then
114  * it is a pointer to a temporary buffer. If the pointer is NULL, then a
115  * local temporary buffer will be allocated (and freed).
116  *
117  * @par Examples:
118  @code
119  double dbuffer[512], cbuffer[256];
120  ...
121  bn_wlt_haar_1d_double_decompose(cbuffer, dbuffer, 512, 1, 1);
122  @endcode
123  *
124  * performs complete decomposition on the data in array "dbuffer".
125  *
126  @code
127  double buffer[3][512]; /_* 512 samples, 3 values/sample (e.g. RGB?)*_/
128  double tbuffer[3][256]; /_* the temporary buffer *_/
129  ...
130  bn_wlt_haar_1d_double_decompose(tbuffer, buffer, 512, 3, 1);
131  @endcode
132  *
133  * This will completely decompose the data in buffer. The first sample will
134  * be the average of all the samples. Alternatively:
135  *
136  * bn_wlt_haar_1d_double_decompose(tbuffer, buffer, 512, 3, 64);
137  *
138  * decomposes buffer into a 64-sample "average image" and 3 "detail" sets.
139  *
140  * bn_wlt_haar_1d_*_reconstruct(tbuffer, buffer, dimen, channels, sub_sz, limit)
141  *
142  */
143 
144 #ifndef BN_WAVELET_H
145 #define BN_WAVELET_H
146 
147 #include "common.h"
148 #include <stdio.h> /* For FILE */
149 #include "bn/defines.h"
150 
152 
153 #define CK_POW_2(dimen) { \
154  register unsigned long j; \
155  register int ok; \
156  for (ok=0, j=0; j < sizeof(unsigned long) * 8; j++) { \
157  if ((unsigned long)(1<<j) == dimen) { ok = 1; break; } \
158  } \
159  if (! ok) { \
160  bu_log("%s:%d value %ld should be power of 2 (2^%ld)\n", \
161  __FILE__, __LINE__, (long)dimen, (long)j); \
162  bu_bomb("CK_POW_2"); \
163  } \
164  }
165 
166 BN_EXPORT extern void bn_wlt_haar_1d_double_decompose(double *tbuf,
167  double *buf,
168  unsigned long dimen,
169  unsigned long depth,
170  unsigned long limit);
171 BN_EXPORT extern void bn_wlt_haar_1d_double_reconstruct(double *tbuf,
172  double *buf,
173  unsigned long dimen,
174  unsigned long depth,
175  unsigned long subimage_size,
176  unsigned long limit);
177 
178 BN_EXPORT extern void bn_wlt_haar_1d_float_decompose(float *tbuf,
179  float *buf,
180  unsigned long dimen,
181  unsigned long depth,
182  unsigned long limit);
183 BN_EXPORT extern void bn_wlt_haar_1d_float_reconstruct(float *tbuf,
184  float *buf,
185  unsigned long dimen,
186  unsigned long depth,
187  unsigned long subimage_size,
188  unsigned long limit);
189 
190 BN_EXPORT extern void bn_wlt_haar_1d_char_decompose(char *tbuf,
191  char *buf,
192  unsigned long dimen,
193  unsigned long depth,
194  unsigned long limit);
195 BN_EXPORT extern void bn_wlt_haar_1d_char_reconstruct(char *tbuf, char *buf,
196  unsigned long dimen,
197  unsigned long depth,
198  unsigned long subimage_size,
199  unsigned long limit);
200 
201 BN_EXPORT extern void bn_wlt_haar_1d_short_decompose(short *tbuf, short *buf,
202  unsigned long dimen,
203  unsigned long depth,
204  unsigned long limit);
205 BN_EXPORT extern void bn_wlt_haar_1d_short_reconstruct(short *tbuf, short *buf,
206  unsigned long dimen,
207  unsigned long depth,
208  unsigned long subimage_size,
209  unsigned long limit);
210 
211 BN_EXPORT extern void bn_wlt_haar_1d_int_decompose(int *tbuf, int *buf,
212  unsigned long dimen,
213  unsigned long depth,
214  unsigned long limit);
215 BN_EXPORT extern void bn_wlt_haar_1d_int_reconstruct(int *tbuf,
216  int *buf,
217  unsigned long dimen,
218  unsigned long depth,
219  unsigned long subimage_size,
220  unsigned long limit);
221 
222 BN_EXPORT extern void bn_wlt_haar_1d_long_decompose(long *tbuf, long *buf,
223  unsigned long dimen,
224  unsigned long depth,
225  unsigned long limit);
226 BN_EXPORT extern void bn_wlt_haar_1d_long_reconstruct(long *tbuf, long *buf,
227  unsigned long dimen,
228  unsigned long depth,
229  unsigned long subimage_size,
230  unsigned long limit);
231 
232 
233 BN_EXPORT extern void bn_wlt_haar_2d_double_decompose(double *tbuf,
234  double *buf,
235  unsigned long dimen,
236  unsigned long depth,
237  unsigned long limit);
238 BN_EXPORT extern void bn_wlt_haar_2d_double_reconstruct(double *tbuf,
239  double *buf,
240  unsigned long dimen,
241  unsigned long depth,
242  unsigned long subimage_size,
243  unsigned long limit);
244 
245 BN_EXPORT extern void bn_wlt_haar_2d_float_decompose(float *tbuf,
246  float *buf,
247  unsigned long dimen,
248  unsigned long depth,
249  unsigned long limit);
250 BN_EXPORT extern void bn_wlt_haar_2d_float_reconstruct(float *tbuf,
251  float *buf,
252  unsigned long dimen,
253  unsigned long depth,
254  unsigned long subimage_size,
255  unsigned long limit);
256 
257 BN_EXPORT extern void bn_wlt_haar_2d_char_decompose(char *tbuf,
258  char *buf,
259  unsigned long dimen,
260  unsigned long depth,
261  unsigned long limit);
262 BN_EXPORT extern void bn_wlt_haar_2d_char_reconstruct(char *tbuf,
263  char *buf,
264  unsigned long dimen,
265  unsigned long depth,
266  unsigned long subimage_size,
267  unsigned long limit);
268 
269 BN_EXPORT extern void bn_wlt_haar_2d_short_decompose(short *tbuf,
270  short *buf,
271  unsigned long dimen,
272  unsigned long depth,
273  unsigned long limit);
274 BN_EXPORT extern void bn_wlt_haar_2d_short_reconstruct(short *tbuf,
275  short *buf,
276  unsigned long dimen,
277  unsigned long depth,
278  unsigned long subimage_size,
279  unsigned long limit);
280 
281 BN_EXPORT extern void bn_wlt_haar_2d_int_decompose(int *tbuf,
282  int *buf,
283  unsigned long dimen,
284  unsigned long depth,
285  unsigned long limit);
286 BN_EXPORT extern void bn_wlt_haar_2d_int_reconstruct(int *tbuf,
287  int *buf,
288  unsigned long dimen,
289  unsigned long depth,
290  unsigned long subimage_size,
291  unsigned long limit);
292 
293 BN_EXPORT extern void bn_wlt_haar_2d_long_decompose(long *tbuf,
294  long *buf,
295  unsigned long dimen,
296  unsigned long depth,
297  unsigned long limit);
298 BN_EXPORT extern void bn_wlt_haar_2d_long_reconstruct(long *tbuf,
299  long *buf,
300  unsigned long dimen,
301  unsigned long depth,
302  unsigned long subimage_size,
303  unsigned long limit);
304 
305 
306 BN_EXPORT extern void bn_wlt_haar_2d_double_decompose2(double *tbuf,
307  double *buf,
308  unsigned long dimen,
309  unsigned long width,
310  unsigned long height,
311  unsigned long limit);
312 BN_EXPORT extern void bn_wlt_haar_2d_double_reconstruct2(double *tbuf,
313  double *buf,
314  unsigned long dimen,
315  unsigned long width,
316  unsigned long height,
317  unsigned long subimage_size,
318  unsigned long limit);
319 
320 BN_EXPORT extern void bn_wlt_haar_2d_float_decompose2(float *tbuf,
321  float *buf,
322  unsigned long dimen,
323  unsigned long width,
324  unsigned long height,
325  unsigned long limit);
326 BN_EXPORT extern void bn_wlt_haar_2d_float_reconstruct2(float *tbuf,
327  float *buf,
328  unsigned long dimen,
329  unsigned long width,
330  unsigned long height,
331  unsigned long subimage_size,
332  unsigned long limit);
333 
334 BN_EXPORT extern void bn_wlt_haar_2d_char_decompose2(char *tbuf,
335  char *buf,
336  unsigned long dimen,
337  unsigned long width,
338  unsigned long height,
339  unsigned long limit);
340 BN_EXPORT extern void bn_wlt_haar_2d_char_reconstruct2(char *tbuf,
341  char *buf,
342  unsigned long dimen,
343  unsigned long width,
344  unsigned long height,
345  unsigned long subimage_size,
346  unsigned long limit);
347 
348 BN_EXPORT extern void bn_wlt_haar_2d_short_decompose2(short *tbuf,
349  short *buf,
350  unsigned long dimen,
351  unsigned long width,
352  unsigned long height,
353  unsigned long limit);
354 BN_EXPORT extern void bn_wlt_haar_2d_short_reconstruct2(short *tbuf,
355  short *buf,
356  unsigned long dimen,
357  unsigned long width,
358  unsigned long height,
359  unsigned long subimage_size,
360  unsigned long limit);
361 
362 BN_EXPORT extern void bn_wlt_haar_2d_int_decompose2(int *tbuf,
363  int *buf,
364  unsigned long dimen,
365  unsigned long width,
366  unsigned long height,
367  unsigned long limit);
368 BN_EXPORT extern void bn_wlt_haar_2d_int_reconstruct2(int *tbuf,
369  int *buf,
370  unsigned long dimen,
371  unsigned long width,
372  unsigned long height,
373  unsigned long subimage_size,
374  unsigned long limit);
375 
376 BN_EXPORT extern void bn_wlt_haar_2d_long_decompose2(long *tbuf,
377  long *buf,
378  unsigned long dimen,
379  unsigned long width,
380  unsigned long height,
381  unsigned long limit);
382 BN_EXPORT extern void bn_wlt_haar_2d_long_reconstruct2(long *tbuf,
383  long *buf,
384  unsigned long dimen,
385  unsigned long width,
386  unsigned long height,
387  unsigned long subimage_size,
388  unsigned long limit);
389 
391 
392 #endif /* BN_WAVELET_H */
393 /** @} */
394 /*
395  * Local Variables:
396  * mode: C
397  * tab-width: 8
398  * indent-tabs-mode: t
399  * c-file-style: "stroustrup"
400  * End:
401  * ex: shiftwidth=4 tabstop=8
402  */
void bn_wlt_haar_2d_char_decompose(char *tbuf, char *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_short_reconstruct2(short *tbuf, short *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_int_reconstruct2(int *tbuf, int *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_long_reconstruct(long *tbuf, long *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_short_decompose2(short *tbuf, short *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)
void bn_wlt_haar_2d_long_decompose2(long *tbuf, long *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)
void bn_wlt_haar_1d_short_reconstruct(short *tbuf, short *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_double_reconstruct(double *tbuf, double *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_int_reconstruct(int *tbuf, int *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_int_reconstruct(int *tbuf, int *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
Header file for the BRL-CAD common definitions.
void bn_wlt_haar_1d_char_decompose(char *tbuf, char *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
ustring width
void bn_wlt_haar_1d_long_decompose(long *tbuf, long *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_char_decompose2(char *tbuf, char *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)
void bn_wlt_haar_2d_int_decompose(int *tbuf, int *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_float_reconstruct(float *tbuf, float *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
#define __BEGIN_DECLS
Definition: common.h:73
void bn_wlt_haar_1d_short_decompose(short *tbuf, short *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_1d_float_reconstruct(float *tbuf, float *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_float_decompose(float *tbuf, float *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_short_decompose(short *tbuf, short *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_char_reconstruct(char *tbuf, char *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_double_decompose(double *tbuf, double *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_char_reconstruct2(char *tbuf, char *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_double_reconstruct(double *tbuf, double *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_long_reconstruct2(long *tbuf, long *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_int_decompose(int *tbuf, int *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_short_reconstruct(short *tbuf, short *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_int_decompose2(int *tbuf, int *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)
void bn_wlt_haar_2d_float_decompose2(float *tbuf, float *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)
#define __END_DECLS
Definition: common.h:74
void bn_wlt_haar_2d_double_decompose(double *tbuf, double *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_long_reconstruct(long *tbuf, long *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_long_decompose(long *tbuf, long *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_float_reconstruct2(float *tbuf, float *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_char_reconstruct(char *tbuf, char *buf, unsigned long dimen, unsigned long depth, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_1d_float_decompose(float *tbuf, float *buf, unsigned long dimen, unsigned long depth, unsigned long limit)
void bn_wlt_haar_2d_double_reconstruct2(double *tbuf, double *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long subimage_size, unsigned long limit)
void bn_wlt_haar_2d_double_decompose2(double *tbuf, double *buf, unsigned long dimen, unsigned long width, unsigned long height, unsigned long limit)