SOPT
Sparse OPTimisation
Functions
sopt::gradient_operator Namespace Reference

Functions

template<typename T >
Vector< T > diff (const Vector< T > &x)
 Numerical derivative of 1d vector. More...
 
template<typename T >
Vector< T > diff_adjoint (const Vector< T > &x)
 Numerical derivative adjoint of 1d vector. More...
 
template<typename T >
Vector< T > diff2d (const Vector< T > &x, const t_int rows, const t_int cols)
 Numerical derivative of 2d image. More...
 
template<typename T >
Vector< T > diff2d_adjoint (const Vector< T > &x, const t_int rows, const t_int cols)
 Numerical derivative adjoint of 2d image. More...
 
template<typename T >
LinearTransform< Vector< T > > gradient_operator (const t_int rows, const t_int cols)
 

Function Documentation

◆ diff()

template<typename T >
Vector<T> sopt::gradient_operator::diff ( const Vector< T > &  x)

Numerical derivative of 1d vector.

Definition at line 11 of file gradient_operator.h.

11  {
12  if (x.size() < 2) return Vector<T>::Zero(x.size());
13  Vector<T> output = Vector<T>::Zero(x.size());
14  output.segment(0, x.size() - 1) = x.segment(1, x.size() - 1) - x.segment(0, x.size() - 1);
15  return output;
16 }
sopt::Vector< Scalar > Vector
Definition: inpainting.cc:28

Referenced by sopt::ScalarRelativeVariation< TYPE >::operator()(), and TEST_CASE().

◆ diff2d()

template<typename T >
Vector<T> sopt::gradient_operator::diff2d ( const Vector< T > &  x,
const t_int  rows,
const t_int  cols 
)

Numerical derivative of 2d image.

Definition at line 27 of file gradient_operator.h.

27  {
28  Matrix<T> output = Matrix<T>::Zero(rows, 2 * cols);
29  const Matrix<T> &input_image = Matrix<T>::Map(x.data(), rows, cols);
30  for (Eigen::Index i(0); i < rows; i++)
31  output.block(0, 0, rows, cols).row(i) = diff<T>(input_image.row(i));
32  for (Eigen::Index i(0); i < cols; i++)
33  output.block(0, cols, rows, cols).col(i) = diff<T>(input_image.col(i));
34  return Vector<T>::Map(output.data(), output.size());
35 }
t_uint rows
t_uint cols
sopt::Matrix< Scalar > Matrix
Definition: inpainting.cc:29

References cols, and rows.

Referenced by gradient_operator().

◆ diff2d_adjoint()

template<typename T >
Vector<T> sopt::gradient_operator::diff2d_adjoint ( const Vector< T > &  x,
const t_int  rows,
const t_int  cols 
)

Numerical derivative adjoint of 2d image.

Definition at line 38 of file gradient_operator.h.

38  {
39  const Matrix<T> &input_image = Matrix<T>::Map(x.data(), rows, 2 * cols);
41  for (Eigen::Index i(0); i < rows; i++)
42  output.row(i) += diff_adjoint<T>(input_image.block(0, 0, rows, cols).row(i));
43  for (Eigen::Index i(0); i < cols; i++)
44  output.col(i) += diff_adjoint<T>(input_image.block(0, cols, rows, cols).col(i));
45  return Vector<T>::Map(output.data(), output.size());
46 }

References cols, and rows.

Referenced by gradient_operator().

◆ diff_adjoint()

template<typename T >
Vector<T> sopt::gradient_operator::diff_adjoint ( const Vector< T > &  x)

Numerical derivative adjoint of 1d vector.

Definition at line 19 of file gradient_operator.h.

19  {
20  Vector<T> output = Vector<T>::Zero(x.size());
21  output.segment(0, x.size() - 1) -= x.segment(0, x.size() - 1);
22  if (output.size() > 2) output.segment(1, x.size() - 1) = x.segment(0, x.size() - 1);
23  return output;
24 }

◆ gradient_operator()

template<typename T >
LinearTransform<Vector<T> > sopt::gradient_operator::gradient_operator ( const t_int  rows,
const t_int  cols 
)

Definition at line 48 of file gradient_operator.h.

48  {
50  [rows, cols](Vector<T> &out, Vector<T> const &x) {
51  assert(x.size() == rows * cols * 2);
52  out = diff2d_adjoint(x, rows, cols) / 2.;
53  assert(out.size() == rows * cols);
54  },
55  {{0, 1, static_cast<t_int>(rows * cols)}},
56  [rows, cols](Vector<T> &out, Vector<T> const &x) {
57  assert(x.size() == rows * cols);
58  out = diff2d(x, rows, cols) / 2.;
59  assert(out.size() == 2 * rows * cols);
60  },
61  {{0, 1, static_cast<t_int>(2 * rows * cols)}});
62 }
Joins together direct and indirect operators.
Vector< T > diff2d(const Vector< T > &x, const t_int rows, const t_int cols)
Numerical derivative of 2d image.
Vector< T > diff2d_adjoint(const Vector< T > &x, const t_int rows, const t_int cols)
Numerical derivative adjoint of 2d image.
int t_int
Root of the type hierarchy for signed integers.
Definition: types.h:13

References cols, diff2d(), diff2d_adjoint(), and rows.