rgsl/wavelet_transforms.rs
1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5/*!
6## Transform Functions
7
8This sections describes the actual functions performing the discrete wavelet transform. Note that the transforms use periodic boundary
9conditions. If the signal is not periodic in the sample length then spurious coefficients will appear at the beginning and end of each
10level of the transform.
11!*/
12
13/// These functions compute in-place forward and inverse discrete wavelet transforms of length n with stride stride on the array data. The
14/// length of the transform n is restricted to powers of two. For the transform version of the function the argument dir can be either
15/// forward (+1) or backward (-1). A workspace work of length n must be provided.
16///
17/// For the forward transform, the elements of the original array are replaced by the discrete wavelet transform f_i -> w_{j,k} in a
18/// packed triangular storage layout, where j is the index of the level j = 0 ... J-1 and k is the index of the coefficient within each
19/// level, k = 0 ... (2^j)-1. The total number of levels is J = \log_2(n). The output data has the following form,
20///
21/// (s_{-1,0}, d_{0,0}, d_{1,0}, d_{1,1}, d_{2,0}, ...,
22/// d_{j,k}, ..., d_{J-1,2^{J-1}-1})
23/// where the first element is the smoothing coefficient s_{-1,0}, followed by the detail coefficients d_{j,k} for each level j. The
24/// backward transform inverts these coefficients to obtain the original data.
25///
26/// These functions return a status of crate::Value::Success upon successful completion. ::Inval is returned if n is not an integer power of
27/// 2 or if insufficient workspace is provided.
28pub mod one_dimension {
29 use crate::Value;
30 use ffi::FFI;
31
32 #[doc(alias = "gsl_wavelet_transform")]
33 pub fn transform(
34 w: &::Wavelet,
35 data: &mut [f64],
36 stride: usize,
37 n: usize,
38 dir: ::WaveletDirection,
39 work: &mut ::WaveletWorkspace,
40 ) -> Result<(), Value> {
41 let ret = unsafe {
42 sys::gsl_wavelet_transform(
43 w.unwrap_shared(),
44 data.as_mut_ptr(),
45 stride,
46 n,
47 dir.into(),
48 work.unwrap_unique(),
49 )
50 };
51 result_handler!(ret, ())
52 }
53
54 #[doc(alias = "gsl_wavelet_transform_forward")]
55 pub fn transform_forward(
56 w: &::Wavelet,
57 data: &mut [f64],
58 stride: usize,
59 n: usize,
60 work: &mut ::WaveletWorkspace,
61 ) -> Result<(), Value> {
62 let ret = unsafe {
63 sys::gsl_wavelet_transform_forward(
64 w.unwrap_shared(),
65 data.as_mut_ptr(),
66 stride,
67 n,
68 work.unwrap_unique(),
69 )
70 };
71 result_handler!(ret, ())
72 }
73
74 #[doc(alias = "gsl_wavelet_transform_inverse")]
75 pub fn transform_inverse(
76 w: &::Wavelet,
77 data: &mut [f64],
78 stride: usize,
79 n: usize,
80 work: &mut ::WaveletWorkspace,
81 ) -> Result<(), Value> {
82 let ret = unsafe {
83 sys::gsl_wavelet_transform_inverse(
84 w.unwrap_shared(),
85 data.as_mut_ptr(),
86 stride,
87 n,
88 work.unwrap_unique(),
89 )
90 };
91 result_handler!(ret, ())
92 }
93}
94
95/// The library provides functions to perform two-dimensional discrete wavelet transforms on square matrices. The matrix dimensions must
96/// be an integer power of two. There are two possible orderings of the rows and columns in the two-dimensional wavelet transform,
97/// referred to as the “standard” and “non-standard” forms.
98///
99/// The “standard” transform performs a complete discrete wavelet transform on the rows of the matrix, followed by a separate complete
100/// discrete wavelet transform on the columns of the resulting row-transformed matrix. This procedure uses the same ordering as a
101/// two-dimensional Fourier transform.
102///
103/// The “non-standard” transform is performed in interleaved passes on the rows and columns of the matrix for each level of the transform.
104/// The first level of the transform is applied to the matrix rows, and then to the matrix columns. This procedure is then repeated across
105/// the rows and columns of the data for the subsequent levels of the transform, until the full discrete wavelet transform is complete.
106/// The non-standard form of the discrete wavelet transform is typically used in image analysis.
107pub mod two_dimension {
108 use crate::Value;
109 use ffi::FFI;
110
111 /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
112 /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
113 /// (square matrix) and are restricted to powers of two. For the transform version of the function the argument dir can be either
114 /// forward (+1) or backward (-1). A workspace work of the appropriate size must be provided. On exit, the appropriate elements of
115 /// the array data are replaced by their two-dimensional wavelet transform.
116 ///
117 /// The functions return a status of crate::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
118 /// equal and integer powers of 2, or if insufficient workspace is provided.
119 #[doc(alias = "gsl_wavelet2d_transform")]
120 pub fn transform(
121 w: &::Wavelet,
122 data: &mut [f64],
123 tda: usize,
124 size1: usize,
125 size2: usize,
126 dir: ::WaveletDirection,
127 work: &mut ::WaveletWorkspace,
128 ) -> Result<(), Value> {
129 let ret = unsafe {
130 sys::gsl_wavelet2d_transform(
131 w.unwrap_shared(),
132 data.as_mut_ptr(),
133 tda,
134 size1,
135 size2,
136 dir.into(),
137 work.unwrap_unique(),
138 )
139 };
140 result_handler!(ret, ())
141 }
142
143 /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
144 /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
145 /// (square matrix) and are restricted to powers of two. For the transform version of the function the argument dir can be either
146 /// forward (+1) or backward (-1). A workspace work of the appropriate size must be provided. On exit, the appropriate elements of
147 /// the array data are replaced by their two-dimensional wavelet transform.
148 ///
149 /// The functions return a status of crate::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
150 /// equal and integer powers of 2, or if insufficient workspace is provided.
151 #[doc(alias = "gsl_wavelet2d_transform_forward")]
152 pub fn transform_forward(
153 w: &::Wavelet,
154 data: &mut [f64],
155 tda: usize,
156 size1: usize,
157 size2: usize,
158 work: &mut ::WaveletWorkspace,
159 ) -> Result<(), Value> {
160 let ret = unsafe {
161 sys::gsl_wavelet2d_transform_forward(
162 w.unwrap_shared(),
163 data.as_mut_ptr(),
164 tda,
165 size1,
166 size2,
167 work.unwrap_unique(),
168 )
169 };
170 result_handler!(ret, ())
171 }
172
173 /// These functions compute two-dimensional in-place forward and inverse discrete wavelet transforms in standard form on the array
174 /// data stored in row-major form with dimensions size1 and size2 and physical row length tda. The dimensions must be equal
175 /// (square matrix) and are restricted to powers of two. For the transform version of the function the argument dir can be either
176 /// forward (+1) or backward (-1). A workspace work of the appropriate size must be provided. On exit, the appropriate elements of
177 /// the array data are replaced by their two-dimensional wavelet transform.
178 ///
179 /// The functions return a status of crate::Value::Success upon successful completion. ::Inval is returned if size1 and size2 are not
180 /// equal and integer powers of 2, or if insufficient workspace is provided.
181 #[doc(alias = "gsl_wavelet2d_transform_inverse")]
182 pub fn transform_inverse(
183 w: &::Wavelet,
184 data: &mut [f64],
185 tda: usize,
186 size1: usize,
187 size2: usize,
188 work: &mut ::WaveletWorkspace,
189 ) -> Result<(), Value> {
190 let ret = unsafe {
191 sys::gsl_wavelet2d_transform_inverse(
192 w.unwrap_shared(),
193 data.as_mut_ptr(),
194 tda,
195 size1,
196 size2,
197 work.unwrap_unique(),
198 )
199 };
200 result_handler!(ret, ())
201 }
202
203 /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
204 #[doc(alias = "gsl_wavelet2d_transform_matrix")]
205 pub fn transform_matrix(
206 w: &::Wavelet,
207 m: &mut crate::MatrixF64,
208 dir: ::WaveletDirection,
209 work: &mut ::WaveletWorkspace,
210 ) -> Result<(), Value> {
211 let ret = unsafe {
212 sys::gsl_wavelet2d_transform_matrix(
213 w.unwrap_shared(),
214 m.unwrap_unique(),
215 dir.into(),
216 work.unwrap_unique(),
217 )
218 };
219 result_handler!(ret, ())
220 }
221
222 /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
223 #[doc(alias = "gsl_wavelet2d_transform_matrix_forward")]
224 pub fn transform_matrix_forward(
225 w: &::Wavelet,
226 m: &mut crate::MatrixF64,
227 work: &mut ::WaveletWorkspace,
228 ) -> Result<(), Value> {
229 let ret = unsafe {
230 sys::gsl_wavelet2d_transform_matrix_forward(
231 w.unwrap_shared(),
232 m.unwrap_unique(),
233 work.unwrap_unique(),
234 )
235 };
236 result_handler!(ret, ())
237 }
238
239 /// These functions compute the two-dimensional in-place wavelet transform on a matrix a.
240 #[doc(alias = "gsl_wavelet2d_transform_matrix_inverse")]
241 pub fn transform_matrix_inverse(
242 w: &::Wavelet,
243 m: &mut crate::MatrixF64,
244 work: &mut ::WaveletWorkspace,
245 ) -> Result<(), Value> {
246 let ret = unsafe {
247 sys::gsl_wavelet2d_transform_matrix_inverse(
248 w.unwrap_shared(),
249 m.unwrap_unique(),
250 work.unwrap_unique(),
251 )
252 };
253 result_handler!(ret, ())
254 }
255
256 /// These functions compute the two-dimensional wavelet transform in non-standard form.
257 #[doc(alias = "gsl_wavelet2d_nstransform")]
258 pub fn nstransform(
259 w: &::Wavelet,
260 data: &mut [f64],
261 tda: usize,
262 size1: usize,
263 size2: usize,
264 dir: ::WaveletDirection,
265 work: &mut ::WaveletWorkspace,
266 ) -> Result<(), Value> {
267 let ret = unsafe {
268 sys::gsl_wavelet2d_nstransform(
269 w.unwrap_shared(),
270 data.as_mut_ptr(),
271 tda,
272 size1,
273 size2,
274 dir.into(),
275 work.unwrap_unique(),
276 )
277 };
278 result_handler!(ret, ())
279 }
280
281 /// These functions compute the two-dimensional wavelet transform in non-standard form.
282 #[doc(alias = "gsl_wavelet2d_nstransform_forward")]
283 pub fn nstransform_forward(
284 w: &::Wavelet,
285 data: &mut [f64],
286 tda: usize,
287 size1: usize,
288 size2: usize,
289 work: &mut ::WaveletWorkspace,
290 ) -> Result<(), Value> {
291 let ret = unsafe {
292 sys::gsl_wavelet2d_nstransform_forward(
293 w.unwrap_shared(),
294 data.as_mut_ptr(),
295 tda,
296 size1,
297 size2,
298 work.unwrap_unique(),
299 )
300 };
301 result_handler!(ret, ())
302 }
303
304 /// These functions compute the two-dimensional wavelet transform in non-standard form.
305 #[doc(alias = "gsl_wavelet2d_nstransform_inverse")]
306 pub fn nstransform_inverse(
307 w: &::Wavelet,
308 data: &mut [f64],
309 tda: usize,
310 size1: usize,
311 size2: usize,
312 work: &mut ::WaveletWorkspace,
313 ) -> Result<(), Value> {
314 let ret = unsafe {
315 sys::gsl_wavelet2d_nstransform_inverse(
316 w.unwrap_shared(),
317 data.as_mut_ptr(),
318 tda,
319 size1,
320 size2,
321 work.unwrap_unique(),
322 )
323 };
324 result_handler!(ret, ())
325 }
326
327 /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
328 #[doc(alias = "gsl_wavelet2d_nstransform_matrix")]
329 pub fn nstransform_matrix(
330 w: &::Wavelet,
331 m: &mut crate::MatrixF64,
332 dir: ::WaveletDirection,
333 work: &mut ::WaveletWorkspace,
334 ) -> Result<(), Value> {
335 let ret = unsafe {
336 sys::gsl_wavelet2d_nstransform_matrix(
337 w.unwrap_shared(),
338 m.unwrap_unique(),
339 dir.into(),
340 work.unwrap_unique(),
341 )
342 };
343 result_handler!(ret, ())
344 }
345
346 /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
347 #[doc(alias = "gsl_wavelet2d_nstransform_matrix_forward")]
348 pub fn nstransform_matrix_forward(
349 w: &::Wavelet,
350 m: &mut crate::MatrixF64,
351 work: &mut ::WaveletWorkspace,
352 ) -> Result<(), Value> {
353 let ret = unsafe {
354 sys::gsl_wavelet2d_nstransform_matrix_forward(
355 w.unwrap_shared(),
356 m.unwrap_unique(),
357 work.unwrap_unique(),
358 )
359 };
360 result_handler!(ret, ())
361 }
362
363 /// These functions compute the non-standard form of the two-dimensional in-place wavelet transform on a matrix a.
364 #[doc(alias = "gsl_wavelet2d_nstransform_matrix_inverse")]
365 pub fn nstransform_matrix_inverse(
366 w: &::Wavelet,
367 m: &mut crate::MatrixF64,
368 work: &mut ::WaveletWorkspace,
369 ) -> Result<(), Value> {
370 let ret = unsafe {
371 sys::gsl_wavelet2d_nstransform_matrix_inverse(
372 w.unwrap_shared(),
373 m.unwrap_unique(),
374 work.unwrap_unique(),
375 )
376 };
377 result_handler!(ret, ())
378 }
379}