Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CornerDetectorKLT.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 "CornerDetectorKLT.hh"
26 #include <Base/Image/ImageConvert.hh>
27 #ifdef BIAS_DEBUG
28 #include <Base/Image/ImageIO.hh>
29 #endif
30 
31  //#define TIME_MEASURE
32 
33 #include <Base/Debug/TimeMeasure.hh>
34 
35 #include <limits.h>
36 #include <algorithm>
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 //////////////////////////////////////////////////////////////////////////
42 // implementation
43 //////////////////////////////////////////////////////////////////////////
44 
45 
46 template <class StorageType, class CalculationType>
49  : CornerDetectorGradient<StorageType, CalculationType>()
50 
51 {
52 }
53 
54 template <class StorageType, class CalculationType>
56 {}
57 
58 
59 
60 //////////////////////////////////////////////////////////////////////////////
61 // protected functions
62 //////////////////////////////////////////////////////////////////////////////
63 
64 
65 template <class StorageType, class CalculationType>
68 {
69 #ifdef BIAS_DEBUG
70  // _FeatureMap is only allocated when this->_Cornerness is allocated
71  BIASASSERT(this->_sgxx.NotBiggerPixelAndSameChannelCount(this->_Cornerness));
72  BIASASSERT(mineig.NotBiggerPixelAndSameChannelCount(this->_Cornerness));
73 #endif
74  int tlx, tly, brx, bry;
75  this->_sgxx.GetROI()->GetCorners(tlx, tly, brx, bry);
76  mineig.GetROI()->SetCorners(tlx, tly, brx, bry);
77  const int minx=tlx;
78  const int miny=tly;
79  const int maxx=brx;
80  const int maxy=bry;
81 
82  register int x, y;
83  register double gxx, gyy, gxy, ev;
84  register CalculationType **ime=mineig.GetImageDataArray();
85  register CalculationType **isgxx=this->_sgxx.GetImageDataArray();
86  register CalculationType **isgxy=this->_sgxy.GetImageDataArray();
87  register CalculationType **isgyy=this->_sgyy.GetImageDataArray();
88 
89 
90  for (y=miny; y<maxy; y++){
91  for (x=minx; x<maxx; x++){
92  gxx=(double)(isgxx[y][x]);
93  gyy=(double)isgyy[y][x];
94  gxy=(double)isgxy[y][x];
95  ev=((gxx+gyy- sqrt((gxx - gyy)*(gxx - gyy)+4.0*gxy*gxy))/2.0);
96  // cerr << ev<<"\t"<<gxx<<"\t"<<gxy<<"\t"<<gyy<<endl;
97  ime[y][x] = (CalculationType)(ev);
98  }
99  }
100  this->_ExtractLocalMaxima(mineig);
101 
102 #ifdef BIAS_DEBUG
103  if (this->DebugLevelIsSet(D_CD_WRITE_DEBUG_IM)){
104  //ImageIO::Save("mineig.mip", mineig);
105  ImageIO::Save("mineig.mip", mineig);
106  }
107 #endif
108  return 0;
109 }
110 
111 //////////////////////////////////////////////////////////////////////////
112 // instantiation
113 //////////////////////////////////////////////////////////////////////////
114 namespace BIAS{
116 template class CornerDetectorKLT<float, float>;
117 
118 // fill in instances as required
119 #ifdef BUILD_IMAGE_INT
121 #endif
122 #ifdef BUILD_IMAGE_CHAR
124 #endif
125 #ifdef BUILD_IMAGE_SHORT
126 #endif
127 #ifdef BUILD_IMAGE_USHORT
129 #ifdef BUILD_IMAGE_INT
131 #endif
132 #endif
133 #ifdef BUILD_IMAGE_UINT
134 #endif
135 #ifdef BUILD_IMAGE_DOUBLE
136 #endif
137 }
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
virtual int _ComputeCornerness(Image< CalculationType > &mineig)
Computes the smaller eigenvalue of the structure tensor A and stores it in _Cornerness.
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
Computes the cornerness as the smaller eigenvalue of the structure tensor matrix. ...
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
bool NotBiggerPixelAndSameChannelCount(const ImageBase &Image) const
checks if data area has bigger or the same &quot;size&quot; as Image of other type
Definition: ImageBase.hh:78
base class for all gradient based corner detectors
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153