37 std::string
const input = argc >= 2 ? argv[1] :
"cameraman256";
38 std::string
const output = argc == 3 ? argv[2] :
"none";
40 std::cout <<
"Usage:\n"
43 <<
" [input [output]]\n\n"
44 "- input: path to the image to clean (or name of standard SOPT image)\n"
45 "- output: filename pattern for output image\n";
49 auto const seed = std::time(
nullptr);
50 std::srand(
static_cast<unsigned int>(seed));
51 std::mt19937
mersenne(std::time(
nullptr));
58 SOPT_HIGH_LOG(
"Image size: {} x {} = {}", image.cols(), image.rows(), image.size());
61 sopt::t_uint const nmeasure = std::floor(0.5 * image.size());
70 auto const psi = sopt::linear_transform<Scalar>(wavelet, image.rows(), image.cols());
71 SOPT_LOW_LOG(
"Wavelet coefficients: {}", (psi.adjoint() * image).size());
74 Vector const y0 = sampling * Vector::Map(image.data(), image.size());
75 auto constexpr snr = 30.0;
76 auto const sigma = y0.stableNorm() / std::sqrt(y0.size()) * std::pow(10.0, -(snr / 20.0));
77 auto const epsilon = std::sqrt(nmeasure + 2 * std::sqrt(y0.size())) *
sigma;
80 std::normal_distribution<> gaussian_dist(0,
sigma);
84 if (output !=
"none") {
87 "dirty_" + output +
".tiff");
97 .regulariser_strength(regulariser_strength)
98 .relative_variation(1e-3)
99 .residual_tolerance(0)
105 auto gp = std::make_shared<sopt::algorithm::L1GProximal<Scalar>>(
false);
106 gp->l1_proximal_tolerance(1e-4)
108 .l1_proximal_itermax(50)
109 .l1_proximal_positivity_constraint(
true)
110 .l1_proximal_real_constraint(
true)
119 auto const diagnostic = fb();
120 SOPT_HIGH_LOG(
"Forward backward returned {}", diagnostic.good);
122 if (output !=
"none")
128 if (not diagnostic.good)
throw std::runtime_error(
"Did not converge!");
130 SOPT_HIGH_LOG(
"SOPT-Forward Backward converged in {} iterations", diagnostic.niters);
An operator that samples a set of measurements.
t_LinearTransform const & Phi() const
Measurement operator.
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