Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CornerDetectorSusan.hh
1 /*
2 This file is distributed as part of the BIAS library (Basic ImageAlgorithmS)
3 but it has not been developed by the authors of BIAS.
4 
5 For copyright, author and license information see below.
6 */
7 
8 
9 /* {{{ Copyright etc. */
10 
11 /**********************************************************************\
12 
13  SUSAN Version 2l by Stephen Smith
14  Oxford Centre for Functional Magnetic Resonance Imaging of the Brain,
15  Department of Clinical Neurology, Oxford University, Oxford, UK
16  (Previously in Computer Vision and Image Processing Group - now
17  Computer Vision and Electro Optics Group - DERA Chertsey, UK)
18  Email: steve@fmrib.ox.ac.uk
19  WWW: http://www.fmrib.ox.ac.uk/~steve
20 
21  (C) Crown Copyright (1995-1999), Defence Evaluation and Research Agency,
22  Farnborough, Hampshire, GU14 6TD, UK
23  DERA WWW site:
24  http://www.dera.gov.uk/
25  DERA Computer Vision and Electro Optics Group WWW site:
26  http://www.dera.gov.uk/imageprocessing/dera/group_home.html
27  DERA Computer Vision and Electro Optics Group point of contact:
28  Dr. John Savage, jtsavage@dera.gov.uk, +44 1344 633203
29 
30  A UK patent has been granted: "Method for digitally processing
31  images to determine the position of edges and/or corners therein for
32  guidance of unmanned vehicle", UK Patent 2272285. Proprietor:
33  Secretary of State for Defence, UK. 15 January 1997
34 
35  This code is issued for research purposes only and remains the
36  property of the UK Secretary of State for Defence. This code must
37  not be passed on without this header information being kept
38  intact. This code must not be sold.
39 
40 \**********************************************************************/
41 
42 /* }}} */
43 /* {{{ Readme First */
44 
45 /**********************************************************************\
46 
47  SUSAN Version 2l
48  SUSAN = Smallest Univalue Segment Assimilating Nucleus
49 
50  Email: steve@fmrib.ox.ac.uk
51  WWW: http://www.fmrib.ox.ac.uk/~steve
52 
53  Related paper:
54  @article{Smith97,
55  author = "Smith, S.M. and Brady, J.M.",
56  title = "{SUSAN} - A New Approach to Low Level Image Processing",
57  journal = "Int. Journal of Computer Vision",
58  pages = "45--78",
59  volume = "23",
60  number = "1",
61  month = "May",
62  year = 1997}
63 
64  To be registered for automatic (bug) updates of SUSAN, send an email.
65 
66  Compile with:
67  gcc -O4 -o susan susan2l.c -lm
68 
69  See following section for different machine information. Please
70  report any bugs (and fixes). There are a few optional changes that
71  can be made in the "defines" section which follows shortly.
72 
73  Usage: type "susan" to get usage. Only PGM format files can be input
74  and output. Utilities such as the netpbm package and XV can be used
75  to convert to and from other formats. Any size of image can be
76  processed.
77 
78  This code is written using an emacs folding mode, making moving
79  around the different sections very easy. This is why there are
80  various marks within comments and why comments are indented.
81 
82 
83  SUSAN QUICK:
84 
85  This version of the SUSAN corner finder does not do all the
86  false-corner suppression and thus is faster and produced some false
87  positives, particularly on strong edges. However, because there are
88  less stages involving thresholds etc., the corners that are
89  correctly reported are usually more stable than those reported with
90  the full algorithm. Thus I recommend at least TRYING this algorithm
91  for applications where stability is important, e.g., tracking.
92 
93  THRESHOLDS:
94 
95  There are two thresholds which can be set at run-time. These are the
96  brightness threshold (t) and the distance threshold (d).
97 
98  SPATIAL CONTROL: d
99 
100  In SUSAN smoothing d controls the size of the Gaussian mask; its
101  default is 4.0. Increasing d gives more smoothing. In edge finding,
102  a fixed flat mask is used, either 37 pixels arranged in a "circle"
103  (default), or a 3 by 3 mask which gives finer detail. In corner
104  finding, only the larger 37 pixel mask is used; d is not
105  variable. In smoothing, the flat 3 by 3 mask can be used instead of
106  a larger Gaussian mask; this gives low smoothing and fast operation.
107 
108  BRIGHTNESS CONTROL: t
109 
110  In all three algorithms, t can be varied (default=20); this is the
111  main threshold to be varied. It determines the maximum difference in
112  greylevels between two pixels which allows them to be considered
113  part of the same "region" in the image. Thus it can be reduced to
114  give more edges or corners, i.e. to be more sensitive, and vice
115  versa. In smoothing, reducing t gives less smoothing, and vice
116  versa. Set t=10 for the test image available from the SUSAN web
117  page.
118 
119  ITERATIONS:
120 
121  With SUSAN smoothing, more smoothing can also be obtained by
122  iterating the algorithm several times. This has a different effect
123  from varying d or t.
124 
125  FIXED MASKS:
126 
127  37 pixel mask: ooo 3 by 3 mask: ooo
128  ooooo ooo
129  ooooooo ooo
130  ooooooo
131  ooooooo
132  ooooo
133  ooo
134 
135  CORNER ATTRIBUTES dx, dy and I
136  (Only read this if you are interested in the C implementation or in
137  using corner attributes, e.g., for corner matching)
138 
139  Corners reported in the corner list have attributes associated with
140  them as well as positions. This is useful, for example, when
141  attempting to match corners from one image to another, as these
142  attributes can often be fairly unchanged between images. The
143  attributes are dx, dy and I. I is the value of image brightness at
144  the position of the corner. In the case of susan_corners_quick, dx
145  and dy are the first order derivatives (differentials) of the image
146  brightness in the x and y directions respectively, at the position
147  of the corner. In the case of normal susan corner finding, dx and dy
148  are scaled versions of the position of the centre of gravity of the
149  USAN with respect to the centre pixel (nucleus).
150 
151  BRIGHTNESS FUNCTION LUT IMPLEMENTATION:
152  (Only read this if you are interested in the C implementation)
153 
154  The SUSAN brightness function is implemented as a LUT
155  (Look-Up-Table) for speed. The resulting pointer-based code is a
156  little hard to follow, so here is a brief explanation. In
157  setup_brightness_lut() the LUT is setup. This mallocs enough space
158  for *bp and then repositions the pointer to the centre of the
159  malloced space. The SUSAN function e^-(x^6) or e^-(x^2) is
160  calculated and converted to a uchar in the range 0-100, for all
161  possible image brightness differences (including negative
162  ones). Thus bp[23] is the output for a brightness difference of 23
163  greylevels. In the SUSAN algorithms this LUT is used as follows:
164 
165  p=in + (i-3)*x_size + j - 1;
166  p points to the first image pixel in the circular mask surrounding
167  point (x,y).
168 
169  cp=bp + in[i*x_size+j];
170  cp points to a position in the LUT corresponding to the brightness
171  of the centre pixel (x,y).
172 
173  now for every pixel within the mask surrounding (x,y),
174  n+=*(cp-*p++);
175  the brightness difference function is found by moving the cp pointer
176  down by an amount equal to the value of the pixel pointed to by p,
177  thus subtracting the two brightness values and performing the
178  exponential function. This value is added to n, the running USAN
179  area.
180 
181  in SUSAN smoothing, the variable height mask is implemented by
182  multiplying the above by the moving mask pointer, reset for each new
183  centre pixel.
184  tmp = *dpt++ * *(cp-brightness);
185 
186 \**********************************************************************/
187 
188 /* }}} */
189 
190 #ifndef __CornerDetectorSusan_hh__
191 #define __CornerDetectorSusan_hh__
192 
193 #include "CornerDetectorBase.hh"
194 
195 #define DEFAULT_THRESH 50
196 #define DEFAULT_QUICK false
197 /// size for non-max corner suppression; SEVEN_SUPP or FIVE_SUPP
198 #define SEVEN_SUPP
199 /// max corners per frame, for susan and our "harris"
200 #define MAX_CORNERS 10000
201 #define CORNERDETECTOR_SUSAN_MAXNUM_DEFAULT 1850
202 
203 namespace BIAS {
204 
205  /**
206  @class cornerstruct
207  @ingroup g_feature
208  @brief used only by Susan corner detector
209  */
210  struct cornerstruct {
211  int x, y, info, dx, dy, I;
212  };
213 
214  typedef struct cornerstruct CORNER_LIST[MAX_CORNERS];
215 
216  /** @class CornerDetectorSusan
217  @ingroup g_feature
218  @brief The Susan corner detector (oxford implementation, see license)
219 
220  See documentation inside CornerDetectorSusan.hh
221  @author woelk 09/2004 */
222  template <class StorageType>
223  class BIASFeatureDetector_EXPORT CornerDetectorSusan
224  : public CornerDetectorBase<StorageType>
225  {
226  public:
229 
230  /** @brief Susan Corner Detector returning homogenous points,
231  @author woelk */
232  virtual int Detect(const Image<StorageType>& image,
233  std::vector<HomgPoint2D>& pvec,
234  std::vector<QUAL>& quality);
235 
236  /** @brief Susan Corner Detector returning corner list,
237  fast interface for daimler
238  @author woelk */
239  int Detect(const Image<StorageType>& image, CORNER_LIST corner_list,
240  int& num);
241 
242  /** @brief Susan Corner Detector returning corner list,
243  only detects corners where roi!=0
244  @author woelk */
245  int Detect(const Image<StorageType>& image, const Image<StorageType>& roi,
246  CORNER_LIST corner_list, int& num);
247 
248  protected:
249  /// parameter
251  bool _Quick;
252 
253  /// local vars for susan
254  int *_cgx, *_cgy, *_r, _susansize, _susanthresh, _num;
255  StorageType *_bp;
256 
257  /// protected function for susan
258  void _int_to_uchar(const int *r, StorageType *in, int size);
259 
260  /// protected function for susan
261  //void _setup_brightness_lut(StorageType **bp, int thresh, int form);
262  void _setup_brightness_lut(int thresh, int form);
263 
264  /// returns the number of corners found
265  int _susan_corners(const StorageType *in, int *r, StorageType *bp,
266  CORNER_LIST corner_list, int x_size,
267  int y_size);
268 
269  /** faster version of the above
270  @author woelk 08 2003 */
271  int _susan_corners(const StorageType *in, int *r, StorageType *bp,
272  CORNER_LIST corner_list, int x_size,
273  int y_size, const StorageType *roi);
274 
275  /// returns the number of corners found
276  int _susan_corners_quick(const StorageType *in, int *r, StorageType *bp,
277  CORNER_LIST corner_list, int x_size,
278  int y_size);
279 
280  /// allocates the internal data structures for susan corner detector
281  inline void _SusanReAllocMem(int x_size, int y_size)
282  {
283  _susansize=x_size*y_size;
284  if (_cgx!=NULL) delete[] _cgx;
285  if (_cgy!=NULL) delete[] _cgy;
286  if (_r!=NULL) delete[] _r;
287  _r = new int[_susansize];
288  _cgx=new int[_susansize];
289  _cgy=new int[_susansize];
290  };
291 
292  }; // class
293 
294 } // namespace
295 
296 
297 #endif // __CornerDetectorSusan_hh__
The Susan corner detector (oxford implementation, see license)
The image template class for specific storage types.
Definition: Image.hh:78
struct cornerstruct CORNER_LIST[MAX_CORNERS]
purly virtual interface defining class for corner detectors
used only by Susan corner detector
void _SusanReAllocMem(int x_size, int y_size)
allocates the internal data structures for susan corner detector