PICCANTE  0.4
The hottest HDR imaging library!
live_wire.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_JNI_LIVE_WIRE_HPP
19 #define PIC_JNI_LIVE_WIRE_HPP
20 
21 #include <functional>
22 #include <vector>
23 
24 #include "../base.hpp"
25 
26 #include "../image.hpp"
27 #include "../filtering/filter_luminance.hpp"
28 #include "../filtering/filter_gradient.hpp"
29 #include "../filtering/filter_log_2d_opt.hpp"
30 #include "../filtering/filter_channel.hpp"
31 #include "../filtering/filter_sampler_2d.hpp"
32 #include "../util/vec.hpp"
33 #include "../util/polyline.hpp"
34 
35 #include "../algorithms/live_wire.hpp"
36 
37 namespace pic {
38 
46 PIC_INLINE std::vector< int > executeLiveWireMultipleJNI(std::string imageInPath, std::vector< int > controlPoints, bool bDownsample)
47 {
48  std::vector< int > out;
49 
50  Image in;
51  bool bRead = in.Read(imageInPath, LT_NOR_GAMMA);
52 
53  if(bRead) {
54  LiveWire *lw ;
55  Image *in_sub = NULL;
56 
57  if(bDownsample) {
59  in_sub = FilterSampler2D::execute(&in, NULL, 0.25f, &isb);
60  lw = new LiveWire(in_sub);
61  } else {
62  lw = new LiveWire(&in);
63  }
64 
65  std::vector< Vec2i > out_tmp;
66 
67  int n = int(controlPoints.size()) >> 1;
68  for(auto i = 0; i < (n - 1); i++) {
69  int indexS = i << 1;
70  int indexE = (i + 1) << 1;
71  Vec2i pS(controlPoints[indexS], controlPoints[indexS + 1]);
72  Vec2i pE(controlPoints[indexE], controlPoints[indexE + 1]);
73 
74  if(bDownsample) {
75  pS[0] = pS[0] >> 2;
76  pS[1] = pS[1] >> 2;
77 
78  pE[0] = pE[0] >> 2;
79  pE[1] = pE[1] >> 2;
80  }
81 
82  lw->execute(pS, pE, out_tmp, true, true);
83  }
84 
85 
86  Polyline2i pl(out_tmp);
87  pl.simplify(32);
88 
89  for(auto i = 0; i < pl.points.size(); i++) {
90  auto point = pl.points.at(i);
91 
92  if(bDownsample) {
93  point[0] = point[0] << 2;
94  point[1] = point[1] << 2;
95  }
96 
97  out.push_back(point[0]);
98  out.push_back(point[1]);
99  }
100 
101  delete lw;
102  }
103 
104  return out;
105 }
106 
107 } // end namespace pic
108 
109 #endif /* PIC_JNI_LIVE_WIRE_HPP */
110 
std::vector< Vec< N, T > > points
Definition: polyline.hpp:45
void execute(Vec2i pS, Vec2i pE, std::vector< Vec2i > &out, bool bConstrained=false, bool bMultiple=false)
execute
Definition: live_wire.hpp:190
#define PIC_INLINE
Definition: base.hpp:33
static Image * execute(Image *imgIn, Image *imgOut, float scale, ImageSampler *isb=NULL)
execute
Definition: filter_sampler_2d.hpp:149
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void simplify(int target_n_points)
simplify
Definition: polyline.hpp:70
Definition: dynamic_range.hpp:29
Definition: live_wire.hpp:37
Definition: bilateral_separation.hpp:25
bool Read(std::string nameFile, LDR_type typeLoad)
Read opens an Image from a file on the disk.
The ImageSamplerBilinear class.
Definition: image_sampler_bilinear.hpp:28
PIC_INLINE std::vector< int > executeLiveWireMultipleJNI(std::string imageInPath, std::vector< int > controlPoints, bool bDownsample)
executeLiveWireMultipleJNI
Definition: live_wire.hpp:46
The Vec class.
Definition: vec.hpp:35
The Polyline class.
Definition: polyline.hpp:41