Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CornerDetectorHarris.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include "CornerDetectorHarris.hh"
26 
27 using namespace std;
28 using namespace BIAS;
29 
30 
31 //////////////////////////////////////////////////////////////////////////
32 // implementation
33 //////////////////////////////////////////////////////////////////////////
34 
35 
36 template <class StorageType, class CalculationType>
39 CornerDetectorGradient<StorageType,CalculationType>()
40 {
41  _Scale = 0.04;
42 }
43 
44 template <class StorageType, class CalculationType>
47 {
48 }
49 
50 template <class StorageType, class CalculationType> int
53 {
54  // preserver ROI
55  int tlx, tly, brx, bry;
56  this->_sgxx.GetROI()->GetCorners(tlx, tly, brx, bry);
57  Cornerness.GetROI()->SetCorners(tlx, tly, brx, bry);
58 
59  const unsigned int minx=tlx;
60  const unsigned int miny=tly;
61  const unsigned int maxx=brx;
62  const unsigned int maxy=bry;
63 
64  const unsigned int width=Cornerness.GetWidth();
65  //const unsigned int height=Cornerness.GetHeight(); not used
66 
67  // work pointers to summed multiplied derivatives
68  CalculationType **psgxx=this->_sgxx.GetImageDataArray(),
69  **psgyy=this->_sgyy.GetImageDataArray(),
70  **psgxy=this->_sgxy.GetImageDataArray();
71  CalculationType *ptr, *end, tmp;
72 
73  // init min und max with impossible values
74  float scale = float ( _Scale );
75  // init all pointers to first usable position (skip upper two lines)
76  unsigned offs = width*miny;
77  unsigned int x=0,y=0;
78  ptr = Cornerness.GetImageData()+offs;
79  end = Cornerness.GetImageData()+width*(maxy);
80  const double me=(double)this->_MinCornerness;
81  Feat fp;
82  this->_FeatList.clear();
83  this->_FeatList.reserve(end-ptr);
84  // run over all pixels, from roi start to end
85  for (y=miny; y<maxy; y++){
86  for (x=minx; x<maxx; x++){
87  const CalculationType xx = (CalculationType)psgxx[y][x];
88  const CalculationType xy = (CalculationType)psgxy[y][x];
89  const CalculationType yy = (CalculationType)psgyy[y][x];
90 
91  //cornerness = det - scale*trace*trace
92  tmp = (CalculationType) (xx*yy-xy*xy - scale * (xx+yy) * (xx+yy));
93 
94  // save highest/lowest values for quality analysis later
95  if (tmp>me){
96  fp.x=x;
97  fp.y=y;
98  fp.val=(tmp>(double)INT_MAX)?(INT_MAX):((int)tmp);
99  this->_FeatList.push_back(fp);
100  //cout <<"Found a point above min cornerness: "<<endl;
101  }
102  *ptr++ = tmp;
103  if (++x>=width){
104  y++;
105  x=0;
106  }
107  }
108  }
109  return 0;
110 }
111 
112 //////////////////////////////////////////////////////////////////////////
113 // instantiation
114 //////////////////////////////////////////////////////////////////////////
115 namespace BIAS{
118 
119 // fill in instances as required
120 #ifdef BUILD_IMAGE_INT
122 #endif
123 #ifdef BUILD_IMAGE_CHAR
125 #endif
126 #ifdef BUILD_IMAGE_SHORT
127 #endif
128 #ifdef BUILD_IMAGE_USHORT
130 #ifdef BUILD_IMAGE_INT
132 #endif
133 #endif
134 #ifdef BUILD_IMAGE_UINT
135 #endif
136 #ifdef BUILD_IMAGE_DOUBLE
137 #endif
138 }
Harris corner detector, detects grey value corners in images.
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
double _Scale
weight of trace in harris approximation
unsigned int GetWidth() const
Definition: ImageBase.hh:312
virtual int _ComputeCornerness(Image< CalculationType > &Cornerness)
Computes the Harris approximation of the smaller eigenvalue of the structure tensor A over the image ...
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
base class for all gradient based corner detectors