KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blob_gss.h
Go to the documentation of this file.
1 #ifndef GSS_INCLUDED_H_
2 #define GSS_INCLUDED_H_
3 
4 #include "l_cpp/l_exception.h"
5 #include "i_cpp/i_image.h"
6 #include <vector>
7 #include <utility>
8 #include <cmath>
9 #include <string>
10 
12 {
13 private:
14  typedef std::vector<kjb::Image> Octave;
15 
16  std::vector<kjb::Image> gss;
17  const int O;
18  const int o_min;
19  const int S;
20  const int s_min;
21  const int s_max;
22  const double sigma_0;
23  const double sigma_n;
24  std::vector<Octave::const_iterator> octaves;
25  std::vector<Octave::const_iterator> x_octaves;
26 
28 
29 private:
31  (
32  int num_octaves,
33  int min_octave,
34  int num_levels,
35  int min_level,
36  int max_level,
37  double initial_sigma,
38  double nominal_sigma
39  );
40 
41 public:
42  const std::vector<kjb::Image>& as_vector() const;
43 
44  std::pair<Octave::const_iterator, Octave::const_iterator> get_octave(int o) const;
45 
46  std::pair<Octave::const_iterator, Octave::const_iterator> get_x_octave(int o) const;
47 
48  std::pair<Octave::const_iterator, Octave::const_iterator> get_octave_at_index(int i_o) const;
49 
50  std::pair<Octave::const_iterator, Octave::const_iterator> get_x_octave_at_index(int i_o) const;
51 
52  int get_num_octaves() const;
53 
54  int get_min_octave() const;
55 
56  int get_num_levels() const;
57 
58  int get_min_level() const;
59 
60  int get_max_level() const;
61 
62  double get_initial_sigma() const;
63 
64  double get_nominal_sigma() const;
65 
66  int get_octave_name(int idx) const;
67 
68  int get_scale_name(int idx) const;
69 
70  double sigma_at(int o, int s) const;
71 
72  double sigma_at_indices(int i_o, int i_s) const;
73 
74  void write(const std::string& base_filename, const std::string& extension);
75 
77 };
78 
80 
81 //----------------------------------------------------------------------------------------
82 // INLINE MEMBER FUNCTIONS ARE DEFINED BELOW
83 //----------------------------------------------------------------------------------------
84 
85 inline
86 GSS::Gaussian_scale_space
87 (
88  int num_octaves,
89  int min_octave,
90  int num_levels,
91  int min_level,
92  int max_level,
93  double initial_sigma,
94  double nominal_sigma
95 ) :
96  O(num_octaves),
97  o_min(min_octave),
98  S(num_levels),
99  s_min(min_level),
100  s_max(max_level),
101  sigma_0(initial_sigma),
102  sigma_n(nominal_sigma)
103 {}
104 
105 //----------------------------------------------------------------------------------------
106 
107 inline
108 const std::vector<kjb::Image>& GSS::as_vector() const
109 {
110  return gss;
111 }
112 
113 //----------------------------------------------------------------------------------------
114 
115 inline
116 std::pair<GSS::Octave::const_iterator, GSS::Octave::const_iterator> GSS::get_octave(int o) const
117 {
118  if(o - o_min < 0 || static_cast<size_t>(o - o_min) >= octaves.size())
119  {
120  KJB_THROW_2(kjb::Index_out_of_bounds, "That octave does not exist");
121  }
122 
123  return std::make_pair(octaves[o - o_min], octaves[o - o_min] + S);
124 }
125 
126 //----------------------------------------------------------------------------------------
127 
128 inline
129 std::pair<GSS::Octave::const_iterator, GSS::Octave::const_iterator> GSS::get_x_octave(int o) const
130 {
131  if(o - o_min < 0 || static_cast<size_t>(o - o_min) >= octaves.size())
132  {
133  KJB_THROW_2(kjb::Index_out_of_bounds, "That octave does not exist");
134  }
135 
136  return std::make_pair(x_octaves[o - o_min], x_octaves[o - o_min] + (s_max - s_min) + 1);
137 }
138 
139 //----------------------------------------------------------------------------------------
140 
141 inline
142 std::pair<GSS::Octave::const_iterator, GSS::Octave::const_iterator> GSS::get_octave_at_index(int i_o) const
143 {
144  return get_octave(i_o + o_min);
145 }
146 
147 //----------------------------------------------------------------------------------------
148 
149 inline
150 std::pair<GSS::Octave::const_iterator, GSS::Octave::const_iterator> GSS::get_x_octave_at_index(int i_o) const
151 {
152  return get_x_octave(i_o + o_min);
153 }
154 
155 //----------------------------------------------------------------------------------------
156 
157 inline
159 {
160  return O;
161 }
162 
163 //----------------------------------------------------------------------------------------
164 
165 inline
167 {
168  return o_min;
169 }
170 
171 //----------------------------------------------------------------------------------------
172 
173 inline
175 {
176  return S;
177 }
178 
179 //----------------------------------------------------------------------------------------
180 
181 inline
183 {
184  return s_min;
185 }
186 
187 //----------------------------------------------------------------------------------------
188 
189 inline
191 {
192  return s_max;
193 }
194 
195 //----------------------------------------------------------------------------------------
196 
197 inline
199 {
200  return sigma_0;
201 }
202 
203 //----------------------------------------------------------------------------------------
204 
205 inline
207 {
208  return sigma_n;
209 }
210 
211 //----------------------------------------------------------------------------------------
212 
213 inline
214 int GSS::get_octave_name(int idx) const
215 {
216  if(idx < 0 || idx >= O)
217  {
218  KJB_THROW_2(kjb::Index_out_of_bounds, "That octave index does not exist.");
219  }
220 
221  return idx + o_min;
222 }
223 
224 //----------------------------------------------------------------------------------------
225 
226 inline
227 int GSS::get_scale_name(int idx) const
228 {
229  if(idx < 0 || idx >= s_max - s_min + 1)
230  {
231  KJB_THROW_2(kjb::Index_out_of_bounds, "That scale index does not exist.");
232  }
233 
234  return idx + s_min;
235 }
236 
237 //----------------------------------------------------------------------------------------
238 
239 inline
240 double GSS::sigma_at(int o, int s) const
241 {
242  return sigma_0 * std::pow(2, o + static_cast<double>(s) / S);
243 }
244 
245 //----------------------------------------------------------------------------------------
246 
247 inline
248 double GSS::sigma_at_indices(int i_o, int i_s) const
249 {
250  return sigma_at(get_octave_name(i_o), get_scale_name(i_s));
251 }
252 
253 //----------------------------------------------------------------------------------------
254 
255 inline
257 {}
258 
259 
260 //----------------------------------------------------------------------------------------
261 
263 {
264 private:
265  int O;
266  int o_min;
267  int S;
268  int s_min;
269  int s_max;
270  double sigma_0;
271  double sigma_n;
272 
273 public:
274  Gaussian_scale_space_generator(int num_octaves, int num_levels, double initial_sigma);
275 
277  (
278  int num_octaves,
279  int min_octave,
280  int num_levels,
281  int min_level,
282  int max_level,
283  double initial_sigma,
284  double nominal_sigma
285  );
286 
288 
289  GSS operator()(const kjb::Image& image);
290 
291  void set_num_octaves(int num_octaves);
292 
293  void set_min_octave(int min_octave);
294 
295  void set_num_levels(int num_levels);
296 
297  void set_min_level(int min_level);
298 
299  void set_max_level(int max_level);
300 
301  void set_initial_sigma(double initial_sigma);
302 
303  void set_nominal_sigma(double nominal_sigma);
304 
305  int get_num_octaves() const;
306 
307  int get_min_octave() const;
308 
309  int get_num_levels() const;
310 
311  int get_min_level() const;
312 
313  int get_max_level() const;
314 
315  double get_initial_sigma() const;
316 
317  double get_nominal_sigma() const;
318 
319 private:
320  void check_params() const;
321 };
322 
324 
325 //----------------------------------------------------------------------------------------
326 // INLINE MEMBER FUNCTIONS ARE DEFINED BELOW
327 //----------------------------------------------------------------------------------------
328 
329 inline
331 (
332  int num_octaves,
333  int num_levels,
334  double initial_sigma
335 ) :
336  O(num_octaves),
337  o_min(0),
338  S(num_levels),
339  s_min(0),
340  s_max(num_levels - 1),
341  sigma_0(initial_sigma),
342  sigma_n(0.0)
343 {
344  check_params();
345 }
346 
347 //----------------------------------------------------------------------------------------
348 
349 inline
351 (
352  int num_octaves,
353  int min_octave,
354  int num_levels,
355  int min_level,
356  int max_level,
357  double initial_sigma,
358  double nominal_sigma
359 ) :
360  O(num_octaves),
361  o_min(min_octave),
362  S(num_levels),
363  s_min(min_level),
364  s_max(max_level),
365  sigma_0(initial_sigma),
366  sigma_n(nominal_sigma)
367 {
368  check_params();
369 }
370 
371 //----------------------------------------------------------------------------------------
372 
373 inline
375 {}
376 
377 //----------------------------------------------------------------------------------------
378 
379 inline
380 void GSS_generator::set_num_octaves(int num_octaves)
381 {
382  O = num_octaves;
383  check_params();
384 }
385 
386 //----------------------------------------------------------------------------------------
387 
388 inline
389 void GSS_generator::set_min_octave(int min_octave)
390 {
391  o_min = min_octave;
392  check_params();
393 }
394 
395 //----------------------------------------------------------------------------------------
396 
397 inline
398 void GSS_generator::set_num_levels(int num_levels)
399 {
400  S = num_levels;
401  check_params();
402 }
403 
404 //----------------------------------------------------------------------------------------
405 
406 inline
407 void GSS_generator::set_min_level(int min_level)
408 {
409  s_min = min_level;
410  check_params();
411 }
412 
413 //----------------------------------------------------------------------------------------
414 
415 inline
416 void GSS_generator::set_max_level(int max_level)
417 {
418  s_max = max_level;
419  check_params();
420 }
421 
422 //----------------------------------------------------------------------------------------
423 
424 inline
425 void GSS_generator::set_initial_sigma(double initial_sigma)
426 {
427  sigma_0 = initial_sigma;
428  check_params();
429 }
430 
431 //----------------------------------------------------------------------------------------
432 
433 inline
434 void GSS_generator::set_nominal_sigma(double nominal_sigma)
435 {
436  sigma_n = nominal_sigma;
437  check_params();
438 }
439 
440 //----------------------------------------------------------------------------------------
441 
442 inline
444 {
445  return O;
446 }
447 
448 //----------------------------------------------------------------------------------------
449 
450 inline
452 {
453  return o_min;
454 }
455 
456 //----------------------------------------------------------------------------------------
457 
458 inline
460 {
461  return S;
462 }
463 
464 //----------------------------------------------------------------------------------------
465 
466 inline
468 {
469  return s_min;
470 }
471 
472 //----------------------------------------------------------------------------------------
473 
474 inline
476 {
477  return s_max;
478 }
479 
480 //----------------------------------------------------------------------------------------
481 
482 inline
484 {
485  return sigma_0;
486 }
487 
488 //----------------------------------------------------------------------------------------
489 
490 inline
492 {
493  return sigma_n;
494 }
495 
496 //----------------------------------------------------------------------------------------
497 
498 inline
499 void GSS_generator::check_params() const
500 {
501  if(O < 1)
502  {
503  KJB_THROW_2(kjb::Illegal_argument, "The number of octaves must be positive.");
504  }
505 
506  if(S < 1)
507  {
508  KJB_THROW_2(kjb::Illegal_argument, "The number of levels must be positive.");
509  }
510 
511  if(s_min >= s_max || s_min >= S)
512  {
513  KJB_THROW_2(kjb::Illegal_argument, "The minimum level must be smaller than the maximum level.");
514  }
515 
516  if(sigma_0 < 0.0 || sigma_n < 0.0)
517  {
518  KJB_THROW_2(kjb::Illegal_argument, "The initial and nominal sigmas must be non-negative.");
519  }
520 
521  if(sigma_n >= sigma_0 * std::pow(2, o_min + static_cast<double>(s_min) / S))
522  {
523  KJB_THROW_2(kjb::Illegal_argument, "The nominal smoothing sigma exceeds that of the minimum scale smoothing.");
524  }
525 }
526 
527 
528 #endif /*GSS_INCLUDED_H_ */
529 
const std::vector< kjb::Image > & as_vector() const
Definition: blob_gss.h:108
void set_nominal_sigma(double nominal_sigma)
Definition: blob_gss.h:434
int get_min_octave() const
Definition: blob_gss.h:166
int get_octave_name(int idx) const
Definition: blob_gss.h:214
int get_min_level() const
Definition: blob_gss.h:182
double get_initial_sigma() const
Definition: blob_gss.h:483
double get_nominal_sigma() const
Definition: blob_gss.h:206
Object thrown when an index argument exceeds the size of a container.
Definition: l_exception.h:399
double get_initial_sigma() const
Definition: blob_gss.h:198
int get_num_levels() const
Definition: blob_gss.h:459
std::pair< Octave::const_iterator, Octave::const_iterator > get_x_octave(int o) const
Definition: blob_gss.h:129
Gaussian_scale_space GSS
Definition: blob_gss.h:79
double sigma_at(int o, int s) const
Definition: blob_gss.h:240
Definition: blob_gss.h:11
int get_max_level() const
Definition: blob_gss.h:190
void set_max_level(int max_level)
Definition: blob_gss.h:416
void set_num_levels(int num_levels)
Definition: blob_gss.h:398
int get_min_octave() const
Definition: blob_gss.h:451
int get_min_level() const
Definition: blob_gss.h:467
Gaussian_scale_space_generator(int num_octaves, int num_levels, double initial_sigma)
Definition: blob_gss.h:331
GSS operator()(const kjb::Image &image)
Definition: blob_gss.cpp:30
int get_max_level() const
Definition: blob_gss.h:475
void set_num_octaves(int num_octaves)
Definition: blob_gss.h:380
int get_num_octaves() const
Definition: blob_gss.h:443
void set_min_octave(int min_octave)
Definition: blob_gss.h:389
void set_min_level(int min_level)
Definition: blob_gss.h:407
int get_scale_name(int idx) const
Definition: blob_gss.h:227
~Gaussian_scale_space_generator()
Definition: blob_gss.h:374
std::pair< Octave::const_iterator, Octave::const_iterator > get_x_octave_at_index(int i_o) const
Definition: blob_gss.h:150
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
double get_nominal_sigma() const
Definition: blob_gss.h:491
void write(const std::string &base_filename, const std::string &extension)
Definition: blob_gss.cpp:5
std::pair< Octave::const_iterator, Octave::const_iterator > get_octave_at_index(int i_o) const
Definition: blob_gss.h:142
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
double sigma_at_indices(int i_o, int i_s) const
Definition: blob_gss.h:248
void set_initial_sigma(double initial_sigma)
Definition: blob_gss.h:425
~Gaussian_scale_space()
Definition: blob_gss.h:256
Code for a wrapper class around the C struct KJB_Image.
Support for error handling exception classes in libKJB.
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
int get_num_octaves() const
Definition: blob_gss.h:158
Definition: blob_gss.h:262
std::pair< Octave::const_iterator, Octave::const_iterator > get_octave(int o) const
Definition: blob_gss.h:116
Gaussian_scale_space_generator GSS_generator
Definition: blob_gss.h:323
int get_num_levels() const
Definition: blob_gss.h:174