PICCANTE  0.4
The hottest HDR imaging library!
filter_nearest_neighbors.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_NEAREST_NEIGHBORS_HPP
19 #define PIC_FILTERING_FILTER_NEAREST_NEIGHBORS_HPP
20 
21 #include "../features_matching/patch_comp.hpp"
22 #include "../filtering/filter.hpp"
23 
24 namespace pic {
25 
30 {
31 protected:
32 
36 
41  void f(FilterFData *data)
42  {
43  int xb, yb;
44  float db = FLT_MAX;
45  for(int i = halfPatchSize; i < height_ps; i+= stride) {
46  for(int j = halfPatchSize; j < width_ps; j+= stride) {
47 
48  float tmp_d = pc->getSSD(data->x, data->y, j, i);
49 
50  if(tmp_d < db) {
51  db = tmp_d;
52  xb = j;
53  yb = i;
54  }
55  }
56  }
57  data->out[0] = float(xb);
58  data->out[1] = float(yb);
59  data->out[1] = db;
60  }
61 
68  Image *setupAux(ImageVec imgIn, Image *imgOut)
69  {
70  height_ps = imgIn[1]->height - halfPatchSize;
71  width_ps = imgIn[1]->width - halfPatchSize;
72 
73  pc = new PatchComp(imgIn[0], imgIn[1], patchSize);
74 
75  return allocateOutputMemory(imgIn, imgOut, bDelete);
76  }
77 
78 public:
79 
84  {
85  pc = NULL;
86  this->minInputImages = 2;
87  }
88 
90  {
91  delete_s(pc);
92  }
93 
102  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
103  {
104  width = imgIn[0]->width;
105  height = imgIn[0]->height;
106  channels = 3;
107  frames = imgIn[0]->frames;
108  }
109 
115  void setup(int patchSize, int stride)
116  {
117  patchSize = (patchSize > 2) ? patchSize : 3;
118 
119  if((patchSize % 2) == 0) {
120  patchSize++;
121  }
122 
123  stride = stride > 0 ? stride : 1;
124 
125  this->stride = stride;
126  this->patchSize = patchSize;
127 
128  pc = delete_s(pc);
129  }
130 };
131 
132 } // end namespace pic
133 
134 #endif /* PIC_FILTERING_FILTER_NEAREST_NEIGHBORS_HPP */
135 
int y
Definition: filter.hpp:39
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int stride
Definition: filter_nearest_neighbors.hpp:34
int halfPatchSize
Definition: filter_nearest_neighbors.hpp:34
The Filter class.
Definition: filter.hpp:50
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_nearest_neighbors.hpp:102
Definition: filter.hpp:37
void setup(int patchSize, int stride)
setup
Definition: filter_nearest_neighbors.hpp:115
The PatchComp class.
Definition: patch_comp.hpp:36
float * out
Definition: filter.hpp:40
float getSSD(int x0, int y0, int x1, int y1)
getSSD
Definition: patch_comp.hpp:177
int height_ps
Definition: filter_nearest_neighbors.hpp:35
Image * setupAux(ImageVec imgIn, Image *imgOut)
setupAux
Definition: filter_nearest_neighbors.hpp:68
int width_ps
Definition: filter_nearest_neighbors.hpp:35
int minInputImages
Definition: filter_radial_basis_function.hpp:56
int x
Definition: filter.hpp:39
Image * allocateOutputMemory(ImageVec imgIn, Image *imgOut, bool bDelete)
allocateOutputMemory
Definition: filter_radial_basis_function.hpp:217
The FilterNearestNeighbors class.
Definition: filter_nearest_neighbors.hpp:29
int patchSize
Definition: filter_nearest_neighbors.hpp:34
~FilterNearestNeighbors()
Definition: filter_nearest_neighbors.hpp:89
The Image class stores an image as buffer of float.
Definition: image.hpp:60
Definition: bilateral_separation.hpp:25
PatchComp * pc
Definition: filter_nearest_neighbors.hpp:33
bool bDelete
Definition: filter_radial_basis_function.hpp:120
void f(FilterFData *data)
f
Definition: filter_nearest_neighbors.hpp:41
FilterNearestNeighbors()
FilterNearestNeighbors.
Definition: filter_nearest_neighbors.hpp:83