18 #ifndef PIC_FILTERING_FILTER_WLS_HPP 19 #define PIC_FILTERING_FILTER_WLS_HPP 21 #include "../filtering/filter.hpp" 23 #ifndef PIC_DISABLE_EIGEN 25 #ifndef PIC_EIGEN_NOT_BUNDLED 26 #include "../externals/Eigen/Sparse" 27 #include "../externals/Eigen/src/SparseCore/SparseMatrix.h" 29 #include <Eigen/Sparse> 30 #include <Eigen/src/SparseCore/SparseMatrix.h> 37 #ifndef PIC_DISABLE_EIGEN 54 int tot = height * width;
57 b = Eigen::VectorXd::Zero(tot);
60 printf(
"Init matrix...");
63 std::vector< Eigen::Triplet< double > > tL;
65 for(
int i = 0; i < height; i++) {
66 int tmpInd = i * width;
68 for(
int j = 0; j < width; j++) {
72 int indI = tmpInd + j;
73 float Lref = L->
data[indI];
83 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
87 if((i + 1) < height) {
91 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
99 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
103 if((j + 1) < width) {
105 Ltmp = L->
data[indJ];
107 tL.push_back(Eigen::Triplet< double > (indI, indJ, tmp));
111 tL.push_back(Eigen::Triplet< double > (indI, indI, 1.0
f - sum));
119 Eigen::SparseMatrix<double> A = Eigen::SparseMatrix<double>(tot, tot);
120 A.setFromTriplets(tL.begin(), tL.end());
122 Eigen::SimplicialCholesky<Eigen::SparseMatrix<double> > solver(A);
125 if(solver.info() != Eigen::Success) {
127 printf(
"SOLVER FAILED!\n");
133 printf(
"SOLVER SUCCESS!\n");
136 #pragma omp parallel for 138 for(
int i = 0; i < tot; i++) {
139 imgOut->
data[i] = float(x(i));
153 Image *img = imgIn[0];
155 int width = img->
width;
157 int tot = height * width;
161 int stridex = width * img->
channels;
164 printf(
"Init matrix...");
167 std::vector< Eigen::Triplet< double > > tL;
169 for(
int i = 0; i < height; i++) {
170 int tmpInd = i * width;
172 for(
int j = 0; j < width; j++) {
177 int indI = tmpInd + j;
181 indJ = indImg - stridex;
184 for(
int p = 0; p < img->
channels; p++) {
185 float tmpDiff = img->
data[indJ + p] - img->
data[indImg + p];
186 diff += tmpDiff * tmpDiff;
191 tL.push_back(Eigen::Triplet< double > (indI, indI - width , tmp));
196 if((i + 1) < height) {
197 indJ = indImg + stridex;
200 for(
int p = 0; p < img->
channels; p++) {
201 float tmpDiff = img->
data[indJ + p] - img->
data[indImg + p];
202 diff += tmpDiff * tmpDiff;
206 tL.push_back(Eigen::Triplet< double > (indI, indI + width , tmp));
214 for(
int p = 0; p < img->
channels; p++) {
215 float tmpDiff = img->
data[indJ + p] - img->
data[indImg + p];
216 diff += tmpDiff * tmpDiff;
220 tL.push_back(Eigen::Triplet< double > (indI, indI - 1 , tmp));
224 if((j + 1) < width) {
228 for(
int p = 0; p < img->
channels; p++) {
229 float tmpDiff = img->
data[indJ + p] - img->
data[indImg + p];
230 diff += tmpDiff * tmpDiff;
235 tL.push_back(Eigen::Triplet< double > (indI, indI + 1 , tmp));
239 tL.push_back(Eigen::Triplet< double > (indI, indI, 1.0
f - sum));
247 Eigen::SparseMatrix<double> A = Eigen::SparseMatrix<double>(tot, tot);
249 A.setFromTriplets(tL.begin(), tL.end());
251 Eigen::SimplicialCholesky< Eigen::SparseMatrix< double > > solver(A);
253 for(
int i = 0; i < imgOut->
channels; i++) {
254 Eigen::VectorXd b, x;
256 b = Eigen::VectorXd::Zero(tot);
257 #pragma omp parallel for 259 for(
int j = 0; j < tot; j++) {
265 if(solver.info() == Eigen::Success) {
268 printf(
"SOLVER SUCCESS!\n");
271 #pragma omp parallel for 273 for(
int j = 0; j < tot; j++) {
278 printf(
"SOLVER FAILED!\n");
342 if(imgIn[0] == NULL) {
353 if(imgIn[0]->channels == 1) {
366 static int main(
int argc,
char* argv[])
369 printf(
"Usage: name_input alpha lambad\n");
373 std::string nameIn = argv[1];
377 float alpha = float(atof(argv[2]));
378 float lambda = float(atof(argv[3]));
380 std::string nameOut = name +
"_wls." + ext;
float alpha
Definition: filter_wls.hpp:287
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
float epsilon
Definition: filter_wls.hpp:287
The Filter class.
Definition: filter.hpp:50
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_wls.hpp:336
Image * multiChannel(ImageVec imgIn, Image *imgOut)
multiChannel applies WLS filter for color images.
Definition: filter_wls.hpp:151
void update(float alpha, float lambda)
update
Definition: filter_wls.hpp:314
FilterWLS()
FilterWLS.
Definition: filter_wls.hpp:294
std::string getExtension(std::string name)
getExtension gets the extension of a file name.
Definition: string.hpp:186
float lambda
Definition: filter_wls.hpp:287
The Image class stores an image as buffer of float.
Definition: image.hpp:60
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
std::string removeExtension(std::string name)
RemoveExtension removes the extension of a string.
Definition: string.hpp:132
virtual Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter.hpp:288
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
FilterWLS(float alpha, float lambda)
FilterWLS.
Definition: filter_wls.hpp:304
Definition: filter_wls.hpp:39
Image * singleChannel(ImageVec imgIn, Image *imgOut)
singleChannel applies WLS smoothing filter for gray-scale images.
Definition: filter_wls.hpp:48
static int main(int argc, char *argv[])
main
Definition: filter_wls.hpp:366