Processing

The Processing module provides useful standard signal processing operations such as convolution and correlation.

Processing can be used with either Matrix, boost's multi_array, or with Blitz++'s Array through BlitzArray.

Interface

Convolution and correlation are implemented in the frequency-domain, using Fourier-transforms. Therefor Fourier.

In order to enable parallel processing, use either OpenMP or define USE_THREADS, but, following the relevant section of the FFTW manual, preferably not both. If neither are defined, the parameter threads will be ignored. The threads parameter refers to the number of threads used by the system threads library, which requires linking extra libraries as explained in the documentation of Fourier.

bool convolute( const Array_t<Tlhs, N> &lhs,
		const Array_t<Trhs, N> &rhs,
		Array_t<Tresult, N> &result,
		unsigned threads = 0u)
Convolution of two N-dimensional arrays lhs and rhs using threads threads. On exit, result will have been resized to the desired dimensions.
bool convolute( const Array_t<Tlhs, N> &lhs,
		const std::vector<Array_t<Trhs, N> > &rhs,
		std::vector<Array_t<Tresult, N> > &result,
		unsigned threads = 0u)
Convolution of N-dimensional arrays lhs and all arrays in the vector in rhs using threads threads. On exit, result will contain as many arrays as rhs, each will have been resized to the desired dimensions. Each array in result will be a convolution of the array in rhs with the same index, and lhs.
bool correlate( const Array_t<Tlhs, N> &lhs,
		const Array_t<Trhs, N> &rhs,
		Array_t<Tresult, N> &result,
		unsigned threads = 0u)
Correlation of two N-dimensional arrays lhs and rhs using threads threads. On exit, result will have been resized to the desired dimensions.
bool correlate( const Array_t<Tlhs, N> &lhs,
		const std::vector<Array_t<Trhs, N> > &rhs,
		std::vector<Array_t<Tresult, N> > &result,
		unsigned threads = 0u)
Correlation of N-dimensional arrays lhs and all arrays in the vector in rhs using threads threads. On exit, result will contain as many arrays as rhs, each will have been resized to the desired dimensions. Each array in result will be a correlation between the array in rhs with the same index, and lhs.
bool autocorrelate(const Array_t<Tlhs, N> &lhs,
		   Array_t<Tresult, N> &result,
		   unsigned threads = 0u)
Auto-correlation of two N-dimensional array lhs, calculated using threads threads. On exit, result will have been resized to the desired dimensions.
bool autocorrelate(const std::vector<Array_t<Trhs, N> > &lhs,
		   std::vector<Array_t<Tresult, N> > &result,
		   unsigned threads = 0u)
Auto-correlation of all N-dimensional arrays in lhs, calculated using threads threads. On exit, result will contain as many arrays as lhs, each will have been resized to the desired dimensions.
bool localAvg( Array_t<Tlhs, N> &lhs, const int radius,
		Array_t<Tresult, N> &result,
		unsigned threads = 0u)
Computes the local average for all elements in lhs using threads threads. On exit, result will have been resized to the dimensions of lhs.
bool localAvg( std::vector<Array_t<Tlhs, N> > &lhs, const int radius,
		std::vector<Array_t<Tresult, N> > &result,
		unsigned threads = 0u)
Computes the local average for all elements in all N-dimensional arrays in lhs using threads threads. On exit, result will contain N-dimensional arrays representing the local averages, each one will be resized to the dimensions of the items in lhs.

Examples

Convolution

const unsigned dims [] = {256u, 256u};
Matrix<int, 2u> image(dims);

// Read image
...

const unsigned maskDims [] = {5, 5};
Matrix<float, 2u> mask(maskDims, 1.0/25.0);

Matrix<float, 2u> result(dims);

// Convolute
const bool ok = convolute(image, mask, result);