PICCANTE  0.4
The hottest HDR imaging library!
filter_channel.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_CHANNEL_HPP
19 #define PIC_FILTERING_FILTER_CHANNEL_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
30 PIC_INLINE std::vector<int> SingleInt(int v0)
31 {
32  std::vector<int> ret;
33  ret.push_back(MAX(v0, 0));
34  return ret;
35 }
36 
44 PIC_INLINE std::vector<int> TripleInt(int v0, int v1, int v2)
45 {
46  std::vector<int> ret;
47  ret.push_back(MAX(v0, 0));
48  ret.push_back(MAX(v1, 0));
49  ret.push_back(MAX(v2, 0));
50  return ret;
51 }
52 
56 class FilterChannel: public Filter
57 {
58 protected:
59 
66  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
67  {
68  int totChannels = CLAMPi(int(channels_vec.size()), 0, src[0]->channels);
69 
70  for(int p = box->z0; p < box->z1; p++) {
71  for(int j = box->y0; j < box->y1; j++) {
72  for(int i = box->x0; i < box->x1; i++) {
73 
74  float *dataOut = (*dst)(i, j, p);
75  float *dataIn = (*src[0])(i, j, p);
76 
77  for(int k = 0; k < totChannels; k++) {
78  int index = channels_vec[k];
79  dataOut[k] = dataIn[index];
80  }
81  }
82  }
83  }
84  }
85 
86  std::vector<int> channels_vec;
87 
88 public:
89 
94  FilterChannel(std::vector<int> channels_vec) : Filter()
95  {
97  }
98 
103  void update(std::vector<int> channels_vec)
104  {
105  this->channels_vec = channels_vec;
106  }
107 
116  void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
117  {
118  width = imgIn[0]->width;
119  height = imgIn[0]->height;
120  channels = MAX(1, int(this->channels_vec.size()));
121  frames = imgIn[0]->frames;
122  }
123 
131  static Image *execute(Image *imgIn, Image *imgOut, int channel = 0)
132  {
133  FilterChannel fltCh(SingleInt(channel));
134  return fltCh.Process(Single(imgIn), imgOut);
135  }
136 
144  static Image *execute(Image *imgIn, Image *imgOut, std::vector<int> channels_vec)
145  {
147  return fltCh.Process(Single(imgIn), imgOut);
148  }
149 
156  static Image *removeAlpha(Image *imgIn, Image *imgOut)
157  {
158  imgOut = execute(imgIn, imgOut, TripleInt(0, 1, 2));
159  return imgOut;
160  }
161 
165  static void test()
166  {
167  Image imgIn(1, 512, 512, 3);
168  imgIn = 1.0f;
169 
170  Image *outR = execute(&imgIn, NULL, SingleInt(0));
171  Image *outG = execute(&imgIn, NULL, SingleInt(1));
172  Image *outB = execute(&imgIn, NULL, SingleInt(2));
173 
174  outR->Write("channel_R.pfm");
175  outG->Write("channel_G.pfm");
176  outB->Write("channel_B.pfm");
177  }
178 };
179 
180 } // end namespace pic
181 
182 #endif /* PIC_FILTERING_FILTER_CHANNEL_HPP */
183 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
static void test()
test
Definition: filter_channel.hpp:165
static Image * execute(Image *imgIn, Image *imgOut, int channel=0)
execute
Definition: filter_channel.hpp:131
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
PIC_INLINE std::vector< int > TripleInt(int v0, int v1, int v2)
TripleInt.
Definition: filter_channel.hpp:44
The Filter class.
Definition: filter.hpp:50
FilterChannel(std::vector< int > channels_vec)
FilterChannel.
Definition: filter_channel.hpp:94
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
int y0
Definition: bbox.hpp:32
static Image * removeAlpha(Image *imgIn, Image *imgOut)
removeAlpha
Definition: filter_channel.hpp:156
void update(std::vector< int > channels_vec)
update
Definition: filter_channel.hpp:103
The FilterChannel class.
Definition: filter_channel.hpp:56
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
#define CLAMPi(x, a, b)
Definition: math.hpp:81
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
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_channel.hpp:66
#define MAX(a, b)
Definition: math.hpp:73
std::vector< int > channels_vec
Definition: filter_channel.hpp:86
PIC_INLINE std::vector< int > SingleInt(int v0)
SingleInt.
Definition: filter_channel.hpp:30
void OutputSize(ImageVec imgIn, int &width, int &height, int &channels, int &frames)
OutputSize.
Definition: filter_channel.hpp:116
int z0
Definition: bbox.hpp:32
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
static Image * execute(Image *imgIn, Image *imgOut, std::vector< int > channels_vec)
execute
Definition: filter_channel.hpp:144