Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LinearRegionDetector.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 "LinearRegionDetector.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 #define MIN_EIGENVALUE_RATIO 4.0
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 // protected functions
61 //////////////////////////////////////////////////////////////////////////////
62 
63 
64 template <class StorageType, class CalculationType>
67 {
68 #ifdef BIAS_DEBUG
69  // _FeatureMap is only allocated when this->_Cornerness is allocated
70  BIASASSERT(this->_Cornerness.SamePixelAndChannelCount(this->_sgxx));
71  BIASASSERT(this->_Cornerness.SamePixelAndChannelCount(mineig));
72 #endif
73  int tlx, tly, brx, bry;
74  this->_sgxx.GetROI()->GetCorners(tlx, tly, brx, bry);
75  mineig.GetROI()->SetCorners(tlx, tly, brx, bry);
76  const int minx=tlx;
77  const int miny=tly;
78  const int maxx=brx;
79  const int maxy=bry;
80 
81  register int x, y;
82  register double gxx, gyy, gxy, ev1, ev2;
83  register const double me=(double)this->_MinCornerness;
84  Feat fp; this->_FeatList.clear();
85  this->_FeatList.reserve((brx-tlx)*(bry-tly));
86  register CalculationType **ime=mineig.GetImageDataArray();
87  register CalculationType **isgxx=this->_sgxx.GetImageDataArray();
88  register CalculationType **isgxy=this->_sgxy.GetImageDataArray();
89  register CalculationType **isgyy=this->_sgyy.GetImageDataArray();
90 
91 
92  for (y=miny; y<maxy; y++){
93  for (x=minx; x<maxx; x++){
94  gxx=(double)(isgxx[y][x]);
95  gyy=(double)isgyy[y][x];
96  gxy=(double)isgxy[y][x];
97  double tmpsqrt = sqrt((gxx - gyy)*(gxx - gyy)+4.0*gxy*gxy);
98  ev1=((gxx+gyy+tmpsqrt)/2.0);
99  ev2=((gxx+gyy-tmpsqrt)/2.0);
100  ime[y][x]=(CalculationType)fabs(ev1/ev2);
101  if ((fabs(ev1/ev2)>MIN_EIGENVALUE_RATIO) && (ev1>me)){
102  double gg=0;
103  for (int i=-2; i<3; i++)
104  for (int j=-2; j<3; j++)
105  gg += (gxx-isgxx[y+i][x+j])*(gxx-isgxx[y+i][x+j])
106  +(gyy-isgyy[y+i][x+j])*(gyy-isgyy[y+i][x+j])
107  +(gxy-isgxy[y+i][x+j])*(gxy-isgxy[y+i][x+j]);
108 
109  if (gg<100000.0) {
110  fp.x=x;
111  fp.y=y;
112  fp.val=(ev1>(double)INT_MAX)?(INT_MAX):((int)ev1);
113  this->_FeatList.push_back(fp);
114  }
115  }
116  }
117  }
118 #ifdef BIAS_DEBUG
119  if (this->DebugLevelIsSet(D_CD_WRITE_DEBUG_IM)){
120  //ImageIO::Save("maxeig.mip", mineig);
121  ImageIO::Save("maxeig.mip", mineig);
122  }
123 #endif
124  return 0;
125 }
126 
127 
128 
129 //////////////////////////////////////////////////////////////////////////
130 // instantiation
131 //////////////////////////////////////////////////////////////////////////
132 namespace BIAS{
133 template class LinearRegionDetector<float, float>;
135 // fill in instances as required
136 #ifdef BUILD_IMAGE_INT
138 #endif
139 #ifdef BUILD_IMAGE_CHAR
140 #endif
141 #ifdef BUILD_IMAGE_SHORT
142 #endif
143 #ifdef BUILD_IMAGE_USHORT
144 #ifdef BUILD_IMAGE_INT
146 #endif
147 #endif
148 #ifdef BUILD_IMAGE_UINT
149 #endif
150 #ifdef BUILD_IMAGE_DOUBLE
151 #endif
152 }
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
try to detect linear regions (const gradient) in images, experimental code for testing ...
virtual int _ComputeCornerness(Image< CalculationType > &im)
Computes the larger eigenvalue of the structure tensor points are accepted only if smaller eigenvalue...
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
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
base class for all gradient based corner detectors
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153