PICCANTE  0.4
The hottest HDR imaging library!
filter_deconvolution.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FILTERING_FILTER_DECONVOLUTION_HPP
19 #define PIC_FILTERING_FILTER_DECONVOLUTION_HPP
20 
21 #include "../base.hpp"
22 
23 #include "../image.hpp"
24 #include "../filtering/filter_conv_2d.hpp"
25 
26 namespace pic {
27 
32 {
33 protected:
39 
41 
42 public:
43 
49  {
50  minInputImages = 2;
51  psf_hat = NULL;
52  img_est_conv = NULL;
53  img_err = NULL;
54  img_rel_blur = NULL;
55  flt_conv = new FilterConv2D();
56 
57  this->nIterations = 0;
59  }
60 
65  void setup(int nIterations)
66  {
67  this->nIterations = nIterations > 0 ? nIterations : 16;
68  }
69 
76  Image *Process(ImageVec imgIn, Image *imgOut)
77  {
78  if (!checkInput(imgIn)) {
79  return imgOut;
80  }
81 
82  imgOut = setupAux(imgIn, imgOut);
83 
84  if (imgOut == NULL) {
85  return imgOut;
86  }
87 
88  //
89  //
90  //
91 
92  Image *psf = imgIn[1];
93 
94  if(psf_hat == NULL) {
95  psf_hat = psf->clone();
96  } else {
97  psf_hat->assign(psf);
98  }
99 
100  psf_hat->flipHV();
101 
102  *imgOut = 0.5f;
103 
106  img_err = allocateOutputMemory(imgIn, img_err, true);
107 
108  ImageVec vec = Double(imgOut, psf);
109  ImageVec vec_err = Double(img_rel_blur, psf_hat);
110 
111  for(int i = 0; i < nIterations; i++) {
112 
113  #ifdef PIC_DEBUG
114  printf("%d\n", i);
115  #endif
116 
118 
119  img_rel_blur->assign(imgIn[0]);
121 
122  img_err = flt_conv->Process(vec_err, img_err);
123 
124  *imgOut *= *img_err;
125  }
126 
127  return imgOut;
128  }
129 
130 
134  static Image *execute(Image *imgIn, Image *psf, Image *imgOut, int nIterations)
135  {
137  return flt.Process(Double(imgIn, psf), imgOut);
138  }
139 };
140 
141 }
142 
143 #endif //PIC_FILTERING_FILTER_DECONVOLUTION_HPP
FilterDeconvolution(int nIterations)
FilterDeconvolution.
Definition: filter_deconvolution.hpp:48
void assign(const Image *imgIn)
assign
int nIterations
Definition: filter_deconvolution.hpp:40
Image * img_est_conv
Definition: filter_deconvolution.hpp:35
The FilterDeconvolution class.
Definition: filter_deconvolution.hpp:31
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
FilterConv2D * flt_conv
Definition: filter_deconvolution.hpp:38
PIC_INLINE ImageVec Double(Image *img1, Image *img2)
Double creates an std::vector which contains img1 and img2; this is for filters input.
Definition: image_vec.hpp:49
int minInputImages
Definition: filter_radial_basis_function.hpp:56
Image * allocateOutputMemory(ImageVec imgIn, Image *imgOut, bool bDelete)
allocateOutputMemory
Definition: filter_radial_basis_function.hpp:217
The FilterConv2D class.
Definition: filter_conv_2d.hpp:30
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Image * clone() const
Clone creates a deep copy of the calling instance.
void setup(int nIterations)
setup
Definition: filter_deconvolution.hpp:65
Image * img_rel_blur
Definition: filter_deconvolution.hpp:37
static Image * execute(Image *imgIn, Image *psf, Image *imgOut, int nIterations)
execute
Definition: filter_deconvolution.hpp:134
Definition: bilateral_separation.hpp:25
void flipHV()
flipHV flips horizontally and vertically the current image.
Definition: image.hpp:220
Image * psf_hat
Definition: filter_deconvolution.hpp:34
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_deconvolution.hpp:76
virtual Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter.hpp:288
bool checkInput(ImageVec &imgIn)
checkInput
Definition: filter.hpp:385
Image * img_err
Definition: filter_deconvolution.hpp:36