18 #ifndef PIC_ALGORITHMS_LISCHINSKI_MINIMIZATION_HPP 19 #define PIC_ALGORITHMS_LISCHINSKI_MINIMIZATION_HPP 21 #ifndef PIC_DISABLE_EIGEN 23 #ifndef PIC_EIGEN_NOT_BUNDLED 24 #include "../externals/Eigen/Sparse" 25 #include "../externals/Eigen/src/SparseCore/SparseMatrix.h" 27 #include <Eigen/Sparse> 28 #include <Eigen/src/SparseCore/SparseMatrix.h> 33 #include "../base.hpp" 34 #include "../image.hpp" 53 float LISCHINSKI_EPSILON = 0.0001f)
55 return -param[1] / (powf(fabsf(Lcur - Lref), param[0]) + LISCHINSKI_EPSILON);
67 return expf(-powf(Lcur - Lref, 2.0f) * 10.0f);
85 float omega_global = 1.0f,
89 float LISCHINSKI_EPSILON = 1e-4f)
91 if(L == NULL || g == NULL) {
95 #ifndef PIC_DISABLE_EIGEN 96 bool bOmega = (omega == NULL);
100 int tot = height * width;
106 Eigen::VectorXd b, x;
107 b = Eigen::VectorXd::Zero(tot);
110 printf(
"Init matrix...");
113 std::vector< Eigen::Triplet< double > > tL;
115 for(
int i = 0; i < height; i++) {
116 int tmpInd = i * width;
118 for(
int j = 0; j < width; j++) {
123 int indI = tmpInd + j;
124 float Lref = L->
data[indI];
128 omega_val = omega_global;
130 omega_val = omega->data[indI];
133 b[indI] = omega_val * g->
data[indI];
138 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
142 if((i + 1) < height) {
145 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
152 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
156 if((j + 1) < width) {
159 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
163 tL.push_back(Eigen::Triplet< double > (indI, indI, omega_val - sum));
171 Eigen::SparseMatrix<double> A = Eigen::SparseMatrix<double>(tot, tot);
172 A.setFromTriplets(tL.begin(), tL.end());
174 Eigen::SimplicialCholesky<Eigen::SparseMatrix<double> > solver(A);
177 if(solver.info() != Eigen::Success) {
179 printf(
"SOLVER FAILED!\n");
185 printf(
"SOLVER SUCCESS!\n");
191 if(!gOut->isSimilarType(g)) {
196 for(
int i = 0; i < height; i++) {
197 int counter = i * width;
199 for(
int j = 0; j < width; j++) {
200 (*gOut)(j, i)[0] =
float(x(counter + j));
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
float LischinskiFunction(float Lcur, float Lref, float param[2], float LISCHINSKI_EPSILON=0.0001f)
LischinskiFunction.
Definition: lischinski_minimization.hpp:52
float LischinskiFunctionGauss(float Lcur, float Lref, float param[2])
LischinskiFunctionGauss.
Definition: lischinski_minimization.hpp:65
PIC_INLINE Image * LischinskiMinimization(Image *L, Image *g, Image *omega=NULL, float omega_global=1.0f, Image *gOut=NULL, float alpha=1.0f, float lambda=0.4f, float LISCHINSKI_EPSILON=1e-4f)
LischinskiMinimization.
Definition: lischinski_minimization.hpp:82
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Image * allocateSimilarOne()
allocateSimilarOne creates an Image with similar size of the calling instance.
Definition: bilateral_separation.hpp:25
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80