Defines | Functions
core/vnl/algo/vnl_convolve.txx File Reference
#include "vnl_convolve.h"
#include <vnl/algo/vnl_fft_1d.h>
#include <vcl_cassert.h>
#include <vcl_iostream.h>

Go to the source code of this file.

Defines

#define vnl_convolve_txx_
#define VNL_CONVOLVE_INSTANTIATE_2(T, U)
#define VNL_CONVOLVE_INSTANTIATE(T, U)

Functions

template<class T1 , class T2 , class U >
vnl_vector< U > vnl_convolve_cyclic_using_fft (vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *)
template<class T1 , class T2 , class U >
vnl_vector< U > vnl_convolve_cyclic (vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *, bool use_fft)
 Cyclically convolve two vnl_vector<T>'s of the same length.
bool has_only_primefactors_2_3_5 (unsigned int n)
template<class T1 , class T2 , class U >
vnl_vector< U > vnl_convolve_using_fft (vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *, int n)
template<class T >
vnl_vector< T > vnl_convolve (vnl_vector< T > const &v1, vnl_vector< T > const &v2, int use_fft)
 Convolve two vnl_vector<T>'s, with the same base type T.
template<class T1 , class T2 , class U >
vnl_vector< U > vnl_convolve (vnl_vector< T1 > const &v1, vnl_vector< T2 > const &v2, U *, int use_fft)
 Convolve two vnl_vector<T>'s, possibly with different base types T.

Define Documentation

#define VNL_CONVOLVE_INSTANTIATE (   T,
 
)
Value:

Definition at line 141 of file vnl_convolve.txx.

#define VNL_CONVOLVE_INSTANTIATE_2 (   T,
 
)
Value:
template vnl_vector<U > vnl_convolve(vnl_vector<T > const&, vnl_vector<U > const&, U*, int); \
template vnl_vector<U > vnl_convolve_cyclic(vnl_vector<T > const&, vnl_vector<U > const&, U*, bool)

Definition at line 137 of file vnl_convolve.txx.

#define vnl_convolve_txx_

Definition at line 3 of file vnl_convolve.txx.


Function Documentation

bool has_only_primefactors_2_3_5 ( unsigned int  n) [inline]

Definition at line 63 of file vnl_convolve.txx.

template<class T >
vnl_vector<T> vnl_convolve ( vnl_vector< T > const &  v1,
vnl_vector< T > const &  v2,
int  use_fft = 0 
)

Convolve two vnl_vector<T>'s, with the same base type T.

The returned vnl_vector has the same base type T, and is identical to the return value of the previous function when T1 = T2 = U.

Definition at line 91 of file vnl_convolve.txx.

template<class T1 , class T2 , class U >
vnl_vector<U> vnl_convolve ( vnl_vector< T1 > const &  v1,
vnl_vector< T2 > const &  v2,
U *  ,
int  use_fft = 0 
)

Convolve two vnl_vector<T>'s, possibly with different base types T.

$res[k] := \displaystyle\sum_{i=-\infty}^{+\infty} v1[k-i] \cdot v2[i]$.

The returned vnl_vector has base type U (the third argument). All calculations are done with type U, so take care! To specify the third argument, pass e.g. a null pointer, casted to U*. Thus: vnl_convolve(v1, v2, (double*)0) would convolve v1 and v2, and return a vnl_vector<double>.

This convolution is non-cyclic, and the length of the result is one less than the sum of the lengths of the two input vectors. But if one of the arguments has length 0, the result has length 0.

When specifying a non-zero 4th argument, FFTs are used to compute the result (see below), which should be identical. The speed of execution may of course differ. In this case both vectors are padded with a sufficient number of zeros, making the length at least that 4th argument, then vnl_convolve_cyclic() is applied.

Definition at line 115 of file vnl_convolve.txx.

template<class T1 , class T2 , class U >
vnl_vector<U> vnl_convolve_cyclic ( vnl_vector< T1 > const &  v1,
vnl_vector< T2 > const &  v2,
U *  ,
bool  use_fft = false 
)

Cyclically convolve two vnl_vector<T>'s of the same length.

$res[k] := \displaystyle\sum_{i=0}^{n-1} v1[k-i] \cdot v2[i]$.

A cyclic convolution requires that the lengths of the input vectors are identical. If this is not the case, an assert failure occurs. The length of the returned vector equals the length of the inputs.

Since the convolution theorem states that a cyclic convolution followed by an FFT is the same as an FFT followed by a multiplication, a cyclic convolution can also be implemented using 3 FFTs on n points and n complex multiplications. By default, vnl_convolve_cyclic does not use FFTs. By specifying "true" as the fourth argument, calculation of the convolution is done using FFTs. This will generally be faster for large n, especially if the vectors are not sparse, and/or if n is a power of 2.

Definition at line 39 of file vnl_convolve.txx.

template<class T1 , class T2 , class U >
vnl_vector<U> vnl_convolve_cyclic_using_fft ( vnl_vector< T1 > const &  v1,
vnl_vector< T2 > const &  v2,
U *   
) [inline]

Definition at line 12 of file vnl_convolve.txx.

template<class T1 , class T2 , class U >
vnl_vector<U> vnl_convolve_using_fft ( vnl_vector< T1 > const &  v1,
vnl_vector< T2 > const &  v2,
U *  ,
int  n 
) [inline]

Definition at line 74 of file vnl_convolve.txx.