36 std::string
const input = argc >= 2 ? argv[1] :
"cameraman256";
37 std::string
const output = argc == 3 ? argv[2] :
"none";
39 std::cout <<
"Usage:\n"
42 <<
" [input [output]]\n\n"
43 "- input: path to the image to clean (or name of standard SOPT image)\n"
44 "- output: filename pattern for output image\n";
48 auto const seed = std::time(
nullptr);
49 std::srand(
static_cast<unsigned int>(seed));
50 std::mt19937
mersenne(std::time(
nullptr));
56 SOPT_HIGH_LOG(
"Image size: {} x {} = {}", image.cols(), image.rows(), image.size());
59 sopt::t_uint const nmeasure = std::floor(0.5 * image.size());
68 auto const psi = sopt::linear_transform<Scalar>(wavelet, image.rows(), image.cols());
69 SOPT_LOW_LOG(
"Wavelet coefficients: {}", (psi.adjoint() * image).size());
72 Vector const y0 = sampling * Vector::Map(image.data(), image.size());
73 auto constexpr snr = 30.0;
74 auto const sigma = y0.stableNorm() / std::sqrt(y0.size()) * std::pow(10.0, -(snr / 20.0));
75 auto const epsilon = std::sqrt(nmeasure + 2 * std::sqrt(y0.size())) *
sigma;
78 std::normal_distribution<> gaussian_dist(0,
sigma);
82 if (output !=
"none") {
85 "dirty_" + output +
".tiff");
88 sopt::t_real constexpr regulariser_strength = 1. / (x_sigma * x_sigma * 2);
95 .regulariser_strength(regulariser_strength)
96 .relative_variation(1e-3)
97 .residual_tolerance(0)
104 Vector const init_map = Vector::Ones(image.size()) * x_sigma;
105 Vector const init_res = y - (sampling * init_map);
106 const std::tuple<Vector, Vector> warm_start = {init_map, init_res};
107 auto const diagnostic = fb();
108 SOPT_HIGH_LOG(
"Forward backward returned {}", diagnostic.good);
110 if (output !=
"none")
116 if (not diagnostic.good)
throw std::runtime_error(
"Did not converge!");
118 SOPT_HIGH_LOG(
"SOPT-Forward Backward converged in {} iterations", diagnostic.niters);
An operator that samples a set of measurements.
L2ForwardBackward &::type Phi(ARGS &&... args)
std::unique_ptr< std::mt19937_64 > mersenne(new std::mt19937_64(0))
#define SOPT_LOW_LOG(...)
Low priority message.
#define SOPT_HIGH_LOG(...)
High priority message.
void set_level(const std::string &level)
Method to set the logging level of the default Log object.
void write_tiff(Image<> const &image, std::string const &filename)
Writes a tiff greyscale file.
Wavelet factory(const std::string &name, t_uint nlevels)
Creates a wavelet transform object.
int t_int
Root of the type hierarchy for signed integers.
Vector< T > dirty(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image, RANDOM &mersenne)
double t_real
Root of the type hierarchy for real numbers.
size_t t_uint
Root of the type hierarchy for unsigned integers.
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
real_type< T >::type epsilon(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
real_type< T >::type sigma(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A matrix of a given type.
sopt::Vector< Scalar > Vector
sopt::Matrix< Scalar > Matrix
sopt::Image< Scalar > Image