Example of image denoising using tgv2_admm class.
#include <string>
#include <Eigen/Core>
#include <Eigen/SparseCore>
#include "image_denoising_common.h"
auto main(int argc, char** argv) -> int {
int sample_image_index = 1;
if (!initialize(argc, argv, sample_image_index)) {
return 1;
}
Eigen::MatrixXd origin;
if (!generate_sample_image(sample_image_index, origin)) {
return 1;
}
Eigen::MatrixXd data = origin;
const Eigen::VectorXd data_vec = data.reshaped<Eigen::ColMajor>();
using coeff_type = Eigen::SparseMatrix<double>;
coeff_type coeff;
coeff.resize(size, size);
coeff.setIdentity();
using derivative_matrix_type = Eigen::SparseMatrix<double>;
const auto first_derivative_matrix =
derivative_matrix_type>(cols, rows);
const auto second_derivative_matrix =
derivative_matrix_type>(cols, rows);
derivative_matrix_type, Eigen::VectorXd>;
solver_type solver;
coeff, first_derivative_matrix, second_derivative_matrix, data_vec);
const auto& initial_solution = data_vec;
solver, data_vec, initial_solution};
Eigen::VectorXd solution_vec = initial_solution;
const Eigen::MatrixXd solution =
solution_vec.reshaped<Eigen::ColMajor>(rows, cols);
visualize_result(
origin, data, solution, "TGV2 Regularization", "tgv2_admm");
return 0;
}
Definition of add_noise function.
Class to search optimal regularization parameter using GCV.
void solve(data_type &solution) const
Solver with the optimal regularization parameter.
void search()
Search the optimal regularization parameter.
Class to solve linear equations with 2nd order total generalized variation (TGV) regularization bredi...
void compute(const Coeff &coeff, const DerivativeMatrix &first_derivative_matrix, const DerivativeMatrix &second_derivative_matrix, const Data &data)
Compute internal parameters.
Definition of implicit_gcv class.
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
auto tgv2_second_derivative_matrix_2d(num_collect::index_type outer_size, num_collect::index_type inner_size) -> Matrix
Create a second derivative matrix for 2nd order TGV regularization in 2D images.
auto sparse_diff_matrix_2d(num_collect::index_type outer_size, num_collect::index_type inner_size) -> Matrix
Create a sparse differential matrix in 2D.
void add_noise(Eigen::MatrixXd &data, double rate)
Add noise to data.
Definition of sparse_diff_matrix_2d function.
Definition of tgv2_admm class.
Definition of the tgv2_second_derivative_matrix_2d function.