PURIFY
Next-generation radio interferometric imaging
Functions
purify::convol Namespace Reference

Functions

template<class T >
Vector< T > zero_pad (const Vector< T > &input, const t_int padding)
 zero pad a vector by a given amount More...
 
template<class T >
Matrix< T > zero_pad (const Matrix< T > &input, const t_int paddingv, const t_int paddingu)
 zero pad a matrix by a given amount More...
 
template<class T >
Vector< T > linear_convol_1d (const Vector< T > &kernelf, const Vector< T > &kernelg)
 1d linear convoluiton of entire signal More...
 
template<class T >
Matrix< T > linear_convol_2d (const Vector< T > &kernelfu, const Vector< T > &kernelfv, const Matrix< T > &kernelg)
 perform linear convolution between two separable kernels and a 2d kernel (vectors) More...
 
template<class T >
Matrix< T > linear_convol_2d (const std::function< T(t_int)> &kernelu, const std::function< T(t_int)> &kernelv, const std::function< T(t_int, t_int)> &kernelw, const t_uint &Jfu, const t_uint &Jfv, const t_uint &Jgu, const t_uint &Jgv)
 perform linear convolution between two separable kernels and a 2d kernel More...
 

Function Documentation

◆ linear_convol_1d()

template<class T >
Vector< T > purify::convol::linear_convol_1d ( const Vector< T > &  kernelf,
const Vector< T > &  kernelg 
)
inline

1d linear convoluiton of entire signal

Definition at line 43 of file convolution.h.

43  {
44  // assumes that Jf has smallest support with kernelf as the filter
45  // assumes that kernelg is zero padded
46  const t_int Jf = kernelf.size();
47  Vector<T> output = Vector<T>::Zero(kernelg.size() - Jf + 1);
48  for (t_int j = 0; j < output.size(); j++)
49  output(j) =
50  (kernelf.segment(0, Jf).array() * kernelg.segment(output.size() - j - 1, Jf).array()).sum();
51  return output;
52 }

Referenced by TEST_CASE().

◆ linear_convol_2d() [1/2]

template<class T >
Matrix< T > purify::convol::linear_convol_2d ( const std::function< T(t_int)> &  kernelu,
const std::function< T(t_int)> &  kernelv,
const std::function< T(t_int, t_int)> &  kernelw,
const t_uint &  Jfu,
const t_uint &  Jfv,
const t_uint &  Jgu,
const t_uint &  Jgv 
)

perform linear convolution between two separable kernels and a 2d kernel

Definition at line 70 of file convolution.h.

73  {
74  Vector<T> kernelfu = Vector<T>::Zero(Jfu);
75  Vector<T> kernelfv = Vector<T>::Zero(Jfv);
76  Matrix<T> kernelg = Matrix<T>::Zero(Jgv, Jgu);
77  for (t_int i = 0; i < kernelg.cols(); i++)
78  for (t_int j = 0; j < kernelg.rows(); j++) kernelg(j, i) = kernelw(j, i);
79  for (t_int i = 0; i < kernelfu.size(); i++) kernelfu(i) = kernelu(i);
80  for (t_int i = 0; i < kernelfv.size(); i++) kernelfv(i) = kernelv(i);
81  return linear_convol_2d<T>(kernelfu, kernelfv, kernelg);
82 }

◆ linear_convol_2d() [2/2]

template<class T >
Matrix< T > purify::convol::linear_convol_2d ( const Vector< T > &  kernelfu,
const Vector< T > &  kernelfv,
const Matrix< T > &  kernelg 
)

perform linear convolution between two separable kernels and a 2d kernel (vectors)

performing convolution for separable kernel

performing convolution for separable kernel

performing convolution for separable kernel

performing convolution for separable kernel

Definition at line 55 of file convolution.h.

56  {
58  Matrix<T> buffer = Matrix<T>::Zero(kernelfv.size() + kernelg.rows() - 1, kernelg.cols());
60  for (t_uint i = 0; i < kernelg.cols(); i++)
61  buffer.col(i) = linear_convol_1d<T>(kernelfv, zero_pad<T>(kernelg.col(i), kernelfv.size() - 1));
62  Matrix<T> output =
63  Matrix<T>::Zero(kernelfv.size() + kernelg.rows() - 1, kernelfu.size() + kernelg.cols() - 1);
64  for (t_uint i = 0; i < output.rows(); i++)
65  output.row(i) = linear_convol_1d<T>(kernelfu, zero_pad<T>(buffer.row(i), kernelfu.size() - 1));
66  return output;
67 }

Referenced by TEST_CASE().

◆ zero_pad() [1/2]

template<class T >
Matrix< T > purify::convol::zero_pad ( const Matrix< T > &  input,
const t_int  paddingv,
const t_int  paddingu 
)
inline

zero pad a matrix by a given amount

Definition at line 35 of file convolution.h.

35  {
36  if ((paddingu < 1) or (paddingv < 1))
37  throw std::runtime_error("Padding must be 1 or greater for convolution.");
38  Matrix<T> output = Matrix<T>::Zero(input.rows() + 2 * paddingv, input.cols() + 2 * paddingu);
39  output.block(paddingv, paddingu, input.rows(), input.cols()) = input;
40  return output;
41 }

◆ zero_pad() [2/2]

template<class T >
Vector< T > purify::convol::zero_pad ( const Vector< T > &  input,
const t_int  padding 
)
inline

zero pad a vector by a given amount

Definition at line 28 of file convolution.h.

28  {
29  if (padding < 1) throw std::runtime_error("Padding must be 1 or greater for convolution.");
30  Vector<T> output = Vector<T>::Zero(input.size() + 2 * padding);
31  output.segment(padding, input.size()) = input;
32  return output;
33 }

Referenced by TEST_CASE().