KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blob_detector.h
Go to the documentation of this file.
1 
5 /*
6  * $Id$
7  */
8 
9 #ifndef BLOB_DETECTOR_INCLUDED
10 #define BLOB_DETECTOR_INCLUDED
11 
12 #include "i_cpp/i_image.h"
13 #include "m_cpp/m_matrix.h"
14 #include "blob_cpp/blob_gss.h"
16 #include <vector>
17 #include <set>
18 #include <cmath>
19 
23 class Blob
24 {
25 public:
26  int row;
27  int col;
28  int size;
29 
33  Blob(int r, int c, int s) :
34  row(r),
35  col(c),
36  size(s)
37  {}
38 
39 #if 0
40 
43  Blob(const Blob& b) :
44  row(b.row),
45  col(b.col),
46  size(b.size)
47  {}
48 
52  Blob& operator=(const Blob& b)
53  {
54  if(&b != this)
55  {
56  row = b.row;
57  col = b.col;
58  size = b.size;
59  }
60  return *this;
61  }
62 #endif
63 };
64 
65 
69 inline
70 bool operator==(const Blob& b1, const Blob& b2)
71 {
72  return b1.size == b2.size && b1.row == b2.row && b1.col == b2.col;
73 }
74 
78 inline
79 bool operator<(const Blob& b1, const Blob& b2)
80 {
81  if(b1.size != b2.size)
82  {
83  return b1.size < b2.size;
84  }
85 
86  if(b1.row != b2.row)
87  {
88  return b1.row < b2.row;
89  }
90 
91  if(b1.col != b2.col)
92  {
93  return b1.col < b2.col;
94  }
95 
96  return false;
97 }
98 
105 inline
107 {
108  double d = std::sqrt(((b1.row - b2.row) * (b1.row - b2.row)) + ((b1.col - b2.col) * (b1.col - b2.col)));
109  return d <= b2.size / 2.0;
110 }
111 
118 inline
120 {
121  double d = std::sqrt(((b1.row - b2.row) * (b1.row - b2.row)) + ((b1.col - b2.col) * (b1.col - b2.col)));
122  return d <= b1.size / 2.0;
123 }
124 
125 typedef std::vector<kjb::Matrix> Matrix_vector;
126 
130 std::vector<Matrix_vector> dog_scale_space(const GSS& gss);
131 
140 {
141 private:
142  int min_blob_size;
143  int max_blob_size;
144  int num_levels;
145  double threshold;
146  std::set<Blob> blobs;
147 
148 public:
152  Blob_detector(int minblobsize, int maxblobsize) :
153  min_blob_size(minblobsize),
154  max_blob_size(maxblobsize),
155  num_levels(3),
156  threshold(7.5)
157  {}
158 
163  (
164  int minblobsize,
165  int maxblobsize,
166  int numlevels,
167  double thresh
168  ) :
169  min_blob_size(minblobsize),
170  max_blob_size(maxblobsize),
171  num_levels(numlevels),
172  threshold(thresh)
173  {}
174 
179  min_blob_size(bd.min_blob_size),
180  max_blob_size(bd.max_blob_size),
181  num_levels(bd.num_levels),
182  threshold(bd.threshold),
183  blobs(bd.blobs)
184  {}
185 
190  {
191  if(&bd != this)
192  {
193  min_blob_size = bd.min_blob_size;
194  max_blob_size = bd.max_blob_size;
195  num_levels = bd.num_levels;
196  threshold = bd.threshold;
197  blobs = bd.blobs;
198  }
199  return *this;
200  }
201 
209  const std::set<Blob>& operator()(const kjb::Image& I);
210 
216  int get_min_blob_size() const
217  {
218  return min_blob_size;
219  }
220 
226  int get_max_blob_size() const
227  {
228  return max_blob_size;
229  }
230 
241  const std::set<Blob>& get_blobs() const
242  {
243  return blobs;
244  }
245 
247 };
248 
249 // helper typedef and function for use of local_argoptima
250 typedef std::vector<std::vector<std::vector<double> > > Vec_vec_vec;
251 Vec_vec_vec matrix_vector_to_vvv(const Matrix_vector& mv);
252 
253 // computes blob parameters from local optima results; for use
254 // with std::transform
256 {
257  const GSS* m_gss;
259 
260  Compute_blob(const GSS* gss, int octave_index) :
261  m_gss(gss),
262  m_octave_index(octave_index)
263  {}
264 
266  {
267  if(&cb != this)
268  {
269  m_gss = cb.m_gss;
271  }
272 
273  return *this;
274  }
275 
276  Blob operator()(int scale_index, int scaled_row, int scaled_col)
277  {
278  return Blob(static_cast<int>(scaled_row * std::pow(2.0, m_gss->get_octave_name(m_octave_index))),
279  static_cast<int>(scaled_col * std::pow(2.0, m_gss->get_octave_name(m_octave_index))),
280  2 * static_cast<int>(m_gss->sigma_at_indices(m_octave_index, scale_index)));
281  }
282 };
283 
284 
285 #endif /*BLOB_DETECTOR_INCLUDED */
286 
int size
Definition: blob_detector.h:28
A simple class that represents a blob.
Definition: blob_detector.h:23
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
int get_octave_name(int idx) const
Definition: blob_gss.h:214
int m_octave_index
Definition: blob_detector.h:258
~Blob_detector()
Definition: blob_detector.h:246
int get_max_blob_size() const
Getter for the max blob size.
Definition: blob_detector.h:226
Vec_vec_vec matrix_vector_to_vvv(const Matrix_vector &mv)
Definition: blob_detector.cpp:35
Definition: blob_gss.h:11
r
Definition: APPgetLargeConnectedEdges.m:127
int col
Definition: blob_detector.h:27
Definition: blob_detector.h:255
std::vector< Matrix_vector > dog_scale_space(const GSS &gss)
Compute the difference of Gaussians (DoG) scale space.
Definition: blob_detector.cpp:13
Blob_detector(int minblobsize, int maxblobsize)
Construct a blob detector with the given max/min blob sizes.
Definition: blob_detector.h:152
Blob(int r, int c, int s)
Construct a blob in (r,c) of size s;.
Definition: blob_detector.h:33
bool blob_center_contained(Blob b1, Blob b2)
Tests whether a blob's center is contained in another blob.
Definition: blob_detector.h:106
Blob operator()(int scale_index, int scaled_row, int scaled_col)
Definition: blob_detector.h:276
std::vector< kjb::Matrix > Matrix_vector
Definition: blob_detector.h:125
for I
Definition: APPgetLargeConnectedEdges.m:141
Compute_blob(const GSS *gss, int octave_index)
Definition: blob_detector.h:260
int get_min_blob_size() const
Getter for the min blob size.
Definition: blob_detector.h:216
Blob_detector(const Blob_detector &bd)
Copy-ctor.
Definition: blob_detector.h:178
std::vector< std::vector< std::vector< double > > > Vec_vec_vec
Definition: blob_detector.h:250
bool blob_center_contains(Blob b1, Blob b2)
Tests whether a blob's center is contained in another blob.
Definition: blob_detector.h:119
bool operator==(const Blob &b1, const Blob &b2)
Compare two blobs; member-wise comparison.
Definition: blob_detector.h:70
const GSS * m_gss
Definition: blob_detector.h:257
const std::set< Blob > & operator()(const kjb::Image &I)
Applies this blob detector to the given image.
Definition: blob_detector.cpp:57
Blob_detector & operator=(const Blob_detector &bd)
Assignment operator. Member-wise assignment.
Definition: blob_detector.h:189
double sigma_at_indices(int i_o, int i_s) const
Definition: blob_gss.h:248
Code for a wrapper class around the C struct KJB_Image.
Wrapped version of the C struct KJB_image.
Definition: i_image.h:76
Compute_blob & operator=(const Compute_blob &cb)
Definition: blob_detector.h:265
const std::set< Blob > & get_blobs() const
Getter for the num_levels.
Definition: blob_detector.h:241
A blob detector class. Use operator() to apply to image.
Definition: blob_detector.h:139
int row
Definition: blob_detector.h:26
bool operator<(const Blob &b1, const Blob &b2)
Lexicographical less than comparison: size, row, col order.
Definition: blob_detector.h:79