PICCANTE  0.4
The hottest HDR imaging library!
grow_cut.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_GL_ALGORITHMS_GROW_CUT_HPP
19 #define PIC_GL_ALGORITHMS_GROW_CUT_HPP
20 
21 #include "../../base.hpp"
22 
23 #include "../../util/std_util.hpp"
24 
25 #include "../../gl/image.hpp"
26 #include "../../gl/image_vec.hpp"
27 
28 #include "../../gl/filtering/filter_op.hpp"
29 #include "../../gl/filtering/filter_max.hpp"
30 #include "../../gl/filtering/filter_grow_cut.hpp"
31 #include "../../gl/filtering/filter_channel.hpp"
32 
33 namespace pic {
34 
35 class GrowCutGL
36 {
37 protected:
43 
44 public:
45 
50  {
51  flt = NULL;
52  fltMax = NULL;
53  img_max = NULL;
54  state_next = NULL;
55  fltSeeds = NULL;
56  fltAssign = NULL;
57  }
58 
60  {
61  delete_s(flt);
67  }
68 
76  {
77  if(strokes == NULL) {
78  return imgOut;
79  }
80 
81  if(!strokes->isValid() && strokes->channels < 3) {
82  return imgOut;
83  }
84 
85  //red --> +1
86  //blue --> -1
87 
88  if(fltSeeds == NULL) {
89  float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
90  float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
91  fltSeeds = new FilterGLOp("vec4(vec3(dot(I0.xyz, C0.xyz) - dot(I0.xyz, C1.xyz)), 1.0)",
92  false, red, blue);
93  }
94 
95  return fltSeeds->Process(SingleGL(strokes), imgOut);
96  }
97 
104  ImageGL *Process(ImageGLVec imgIn, ImageGL *imgOut = NULL)
105  {
106  if(!ImageGLVecCheck(imgIn, 2)) {
107  return imgOut;
108  }
109 
110  auto img = imgIn[0];
111  auto seeds = imgIn[1];
112 
113  if(imgOut == NULL) {
114  imgOut = new ImageGL(1, img->width, img->height, 3, IMG_GPU, GL_TEXTURE_2D);
115  }
116 
117  if(fltMax == NULL) {
118  fltMax = new FilterGLMax(5);
119  }
120 
121  if(flt == NULL) {
122  flt = new FilterGLGrowCut();
123  }
124 
125  auto state_cur = imgOut;
126 
127  if(state_next == NULL) {
128  state_next = state_cur->allocateSimilarOneGL();
129  }
130 
131  //compute max
133 
134  if(fltAssign == NULL) {
135  fltAssign = new FilterGLOp("vec4(I0.x, abs(I0.x) > 0.0 ? 1.0 : 0.0, 0.0, 1.0)", false, NULL, NULL);
136  }
137 
138  state_cur = fltAssign->Process(SingleGL(seeds), state_cur);
139 
140  //iterative filtering...
141  int iterations = int(img->getDiagonalSize());
142 
143  if((iterations % 2) == 1) {
144  iterations++;
145  }
146 
147  ImageGLVec input = TripleGL(state_cur, img, img_max);
148  ImageGL *output = state_next;
149 
150  for(int i = 0; i < iterations; i++) {
151  output = flt->Process(input, output);
152 
153  auto tmp = input[0];
154  input[0] = output;
155  output = tmp;
156  }
157 
158  return imgOut;
159  }
160 
161 };
162 
163 } // end namespace pic
164 
165 #endif /* PIC_GL_ALGORITHMS_GROW_CUT_HPP */
166 
int channels
Definition: filter_radial_basis_function.hpp:80
ImageGL * img_max
Definition: grow_cut.hpp:42
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
Definition: grow_cut.hpp:35
GrowCutGL()
GrowCutGL.
Definition: grow_cut.hpp:49
~GrowCutGL()
Definition: grow_cut.hpp:59
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
Definition: filter_radial_basis_function.hpp:1148
PIC_INLINE ImageGLVec SingleGL(ImageGL *img)
SingleGL creates a single for filters input.
Definition: image_vec.hpp:39
Definition: filter_op.hpp:28
FilterGLOp * fltAssign
Definition: grow_cut.hpp:41
The FilterGLGrowCut class.
Definition: filter_grow_cut.hpp:28
ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: filter_npasses.hpp:323
FilterGLGrowCut * flt
Definition: grow_cut.hpp:38
ImageGL * fromStrokeImageToSeeds(ImageGL *strokes, ImageGL *imgOut)
fromStrokeImageToSeeds
Definition: grow_cut.hpp:75
The ImageGL class.
Definition: image.hpp:42
ImageGL * allocateSimilarOneGL()
allocateSimilarOneGL
virtual ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut)
Process.
Definition: display.hpp:258
ImageGL * Process(ImageGLVec imgIn, ImageGL *imgOut=NULL)
Process.
Definition: grow_cut.hpp:104
FilterGLOp * fltSeeds
Definition: grow_cut.hpp:40
The FilterGLMax class.
Definition: filter_max.hpp:31
PIC_INLINE ImageGLVec TripleGL(ImageGL *img1, ImageGL *img2, ImageGL *img3)
TripleGL creates a triple for filters input.
Definition: image_vec.hpp:67
FilterGLMax * fltMax
Definition: grow_cut.hpp:39
Definition: bilateral_separation.hpp:25
ImageGL * state_next
Definition: grow_cut.hpp:42
Definition: image.hpp:37
PIC_INLINE bool ImageGLVecCheck(ImageGLVec &imgIn, int minInputImages)
ImageGLVecCheck.
Definition: image_vec.hpp:82
std::vector< ImageGL * > ImageGLVec
ImageGLVec an std::vector of pic::ImageGL.
Definition: image_vec.hpp:32