SOPT
Sparse OPTimisation
cpp
tools_for_tests
inpainting.h
Go to the documentation of this file.
1
#ifndef SOPT_TOOLS_FOR_TESTS_INPAINTING_H
2
#define SOPT_TOOLS_FOR_TESTS_INPAINTING_H
3
4
#include "sopt/config.h"
5
#include <random>
6
#include "
sopt/linear_transform.h
"
7
#include "
sopt/types.h
"
8
9
namespace
sopt
{
10
11
template
<
typename
T>
12
Vector<T>
target
(
sopt::LinearTransform
<
Vector<T>
>
const
&sampling,
sopt::Image<T>
const
&image) {
13
return
sampling *
Vector<T>::Map
(image.data(), image.size());
14
}
15
16
template
<
typename
T>
17
typename
real_type<T>::type
sigma
(
sopt::LinearTransform
<
Vector<T>
>
const
&sampling,
18
sopt::Image<T>
const
&image) {
19
auto
constexpr snr = 30.0;
20
auto
const
y0 =
target
(sampling, image);
21
return
y0.stableNorm() / std::sqrt(y0.size()) * std::pow(10.0, -(snr / 20.0));
22
}
23
24
template
<
typename
T,
typename
RANDOM>
25
Vector<T>
dirty
(
sopt::LinearTransform
<
Vector<T>
>
const
&sampling,
sopt::Image<T>
const
&image,
26
RANDOM &
mersenne
) {
27
// values near the mean are the most likely
28
// standard deviation affects the dispersion of generated values from the mean
29
auto
const
y0 =
target
(sampling, image);
30
std::normal_distribution<> gaussian_dist(0,
sigma
(sampling, image));
31
Vector<T>
y(y0.size());
32
for
(
t_int
i = 0; i < y0.size(); i++) y(i) = y0(i) + gaussian_dist(
mersenne
);
33
34
return
y;
35
}
36
37
template
<
typename
T>
38
typename
real_type<T>::type
epsilon
(
sopt::LinearTransform
<
Vector<T>
>
const
&sampling,
39
sopt::Image<T>
const
&image) {
40
auto
const
y0 =
target
(sampling, image);
41
auto
const
nmeasure = y0.size();
42
return
std::sqrt(nmeasure + 2 * std::sqrt(nmeasure)) *
sigma
(sampling, image);
43
}
44
}
// namespace sopt
45
#endif
sopt::LinearTransform
Joins together direct and indirect operators.
Definition:
linear_transform.h:30
sopt::details::underlying_value_type
Computes inner-most element type.
Definition:
real_type.h:42
mersenne
std::unique_ptr< std::mt19937_64 > mersenne(new std::mt19937_64(0))
linear_transform.h
sopt
Definition:
bisection_method.h:10
sopt::t_int
int t_int
Root of the type hierarchy for signed integers.
Definition:
types.h:13
sopt::dirty
Vector< T > dirty(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image, RANDOM &mersenne)
Definition:
inpainting.h:25
sopt::Image
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Definition:
types.h:39
sopt::target
Vector< T > target(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition:
inpainting.h:12
sopt::epsilon
real_type< T >::type epsilon(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition:
inpainting.h:38
sopt::Vector
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
Definition:
types.h:24
sopt::sigma
real_type< T >::type sigma(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition:
inpainting.h:17
types.h
Generated by
1.9.1