Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HessianSimple.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 
26 #include "HessianSimple.hh"
27 #include "FilterMask.hh"
28 
29 using namespace BIAS;
30 using namespace std;
31 
32 namespace BIAS {
33 
34 #define POLAR_TABLE_OFFSET 128
35 #define POLAR_TABLE_SIZE 257
36 //////////////////////////////////////////////////////////////////////////
37 // implementation
38 //////////////////////////////////////////////////////////////////////////
39 template <class InputStorageType, class OutputStorageType> void
42 {
43  // this is a filtermask in the sense of convolution
44  // it is reflected at its symmetry center before being "dropped"
45  // onto the image !
46  Vector<FM_INT> h(3), v(1);
47  h[0] = 1;
48  h[1] = -2;
49  h[2] = 1;
50  v[0] = 1;
51  FilterMask f(h, v, 0, 0);
53  _Conv.SetKernel(f);
54 }
55 
56 template <class InputStorageType, class OutputStorageType>
58 HessianSimple(bool BuildPCM)
59  : FilterNTo3N<InputStorageType, OutputStorageType>()
60 {
61  InitKernel_();
62 }
63 
64 template <class InputStorageType, class OutputStorageType>
67  : _Conv(other._Conv)
68 
69 {
70  InitKernel_();
71 }
72 
73 template <class InputStorageType, class OutputStorageType>
76 {
77 
78 }
79 
80 template <class InputStorageType, class OutputStorageType>
84 {
85  BIASCDOUT(D_FILTERBASE_CALLSTACK, "HessianSimple::Filter(src, gx, gy)\n");
86  int res=0;
87  if (!hxx.SamePixelAndChannelCount(src)){
88  hxx.Release();
89  hxx.Init(src.GetWidth(), src.GetHeight(), src.GetChannelCount());
90  }
91  if (!hyy.SamePixelAndChannelCount(src)){
92  hyy.Release();
93  hyy.Init(src.GetWidth(), src.GetHeight(), src.GetChannelCount());
94  }
95 
96  if (src.GetChannelCount()==1) {
97  if (_Conv.CalculationInFloat()){
98  res = SimpleGreyValidFloat_(src, hxx, hyy);
99  } else {
100  res = SimpleGreyValidInt_(src, hxx, hyy);
101  }
102  } else {
103  // grest
104  BIASERR("not for multiple channel images");
105  return -5;
106  }
107  return res;
108 }
109 
110 template <class InputStorageType, class OutputStorageType>
114 {
115  BIASCDOUT(D_FILTERBASE_CALLSTACK,
116  "HessianSimple::Filter(src, hxx, hyyy, hxy)\n");
117  if (!src.SamePixelAndChannelCount(hxy)){
118  if (!hxy.IsEmpty()) hxy.Release();
119  hxy.Init(src.GetWidth(), src.GetHeight(), src.GetChannelCount());
120  }
121 
122  int res=0;
123  res = Filter(src, hxx, hyy);
124  OutputStorageType **idaHxx = hxx.GetImageDataArray();
125  OutputStorageType **idaHyy = hyy.GetImageDataArray();
126  OutputStorageType **idaHxy = hxy.GetImageDataArray();
127 
128  for(unsigned int x=0;x<hxx.GetWidth();x++){
129  for(unsigned int y=0;y<hxx.GetHeight();y++){
130  idaHxy[y][x] = idaHxx[y][x] + idaHyy[y][x];
131  }
132  }
133 
134  return (res==0)?0:-1;
135 }
136 
137 
138 
139 
140 template <class InputStorageType, class OutputStorageType>
145 {
146  BIASCDOUT(D_FILTERBASE_CALLSTACK, "HessianSimple::SimpleGreyValidFloat_\n");
147 
148  OutputStorageType *gx=gWE.GetImageData();
149  OutputStorageType *gy=gNS.GetImageData();
150  const int width=(int)src.GetWidth();
151  const int nwidth = - width;
152 
153 #ifdef BIAS_DEBUG
154  BIASASSERT(src.GetChannelCount()==1);
155  BIASASSERT(src.SamePixelAndChannelCount(gWE));
156  BIASASSERT(src.SamePixelAndChannelCount(gNS));
157  BIASASSERT(gx!=gy);
158  BIASASSERT(_Conv.CalculationInFloat());
159 #endif
160 
161  int minx, miny, maxx, maxy;
162  src.GetROI()->GetCorners(minx, miny, maxx, maxy);
163  gWE.GetROI()->SetCorners(minx+1, miny+1, maxx-1, maxy-1);
164  gNS.GetROI()->SetCorners(minx+1, miny+1, maxx-1, maxy-1);
165 
166 
167  int offset;
168  OutputStorageType *pgx, *pgy, *end2, *lend2;
169 
170 
171  int step=width-maxx+minx;
172 
173  offset=minx+1+(miny+1)*width;
174  const InputStorageType *ph = src.GetImageData() + offset;
175  pgx=gx+offset;
176  pgy=gy+offset;
177  step+=2;
178  end2=gx+maxx+width*(maxy-2)-1;
179  lend2=gx+maxx+width*(miny+1)-1;
180  while (pgx<end2){
181  while (pgx<lend2){
182  *pgx++ = (OutputStorageType)(ph[1] - ph[-1])/
183  (OutputStorageType)2;
184  *pgy++ = (OutputStorageType)(ph[width] - ph[nwidth])/
185  (OutputStorageType)2;
186  ph++;
187  }
188  ph+=step;
189  pgx+=step;
190  pgy+=step;
191  lend2+=width;
192  }
193  return 0;
194 }
195 
196 
197 template <class InputStorageType, class OutputStorageType>
202 {
203  BIASCDOUT(D_FILTERBASE_CALLSTACK, "HessianSimple::SimpleGreyValidInt_\n");
204 
205  OutputStorageType *gx=gWE.GetImageData();
206  OutputStorageType *gy=gNS.GetImageData();
207  const int width=(int)src.GetWidth();
208  const int nwidth = - width;
209 
210 #ifdef BIAS_DEBUG
211  BIASASSERT(src.GetChannelCount()==1);
212  BIASASSERT(src.SamePixelAndChannelCount(gWE));
213  BIASASSERT(src.SamePixelAndChannelCount(gNS));
214  BIASASSERT(gx!=gy);
215  BIASASSERT(!_Conv.CalculationInFloat());
216 #endif
217 
218 
219 
220  int minx, miny, maxx, maxy;
221  src.GetROI()->GetCorners(minx, miny, maxx, maxy);
222  gWE.GetROI()->SetCorners(minx+1, miny+1, maxx-1, maxy-1);
223  gNS.GetROI()->SetCorners(minx+1, miny+1, maxx-1, maxy-1);
224 
225 
226  int offset;
227  OutputStorageType *pgx, *pgy, *end2, *lend2;
228 
229 
230  int step=width-maxx+minx;
231 
232  offset=minx+1+(miny+1)*width;
233  const InputStorageType * ph = src.GetImageData()+offset;
234 
235  pgx=gx+offset;
236  pgy=gy+offset;
237  step+=2;
238  end2=gx+maxx+width*(maxy-2)-1;
239  lend2=gx+maxx+width*(miny+1)-1;
240  while (pgx<end2){
241  while (pgx<lend2){
242  *pgx++ = (OutputStorageType)(ph[1] - ph[-1])/
243  (OutputStorageType)2;
244  *pgy++ = (OutputStorageType)(ph[width] - ph[nwidth])/
245  (OutputStorageType)2;
246  ph++;
247  }
248  ph+=step;
249  pgx+=step;
250  pgy+=step;
251  lend2+=width;
252  }
253 
254  return 0;
255 }
256 
257 
258 template <class InputStorageType, class OutputStorageType>
260 GetBordersValid_(int &border_x, int &border_y) const
261 {
262  _Conv.GetBorders(border_x, border_y);
263 }
264 
265 //////////////////////////////////////////////////////////////////////////
266 // instantiation
267 //////////////////////////////////////////////////////////////////////////
268 #define FILTER_INSTANTIATION_CLASS HessianSimple
269 #define FILTER_INSTANTIATION_NO_UNSIGNED_OUTPUT
270 #include "Filterinst.hh"
271 
272 } // namespace BIAS
void Release()
reimplemented from ImageBase
Definition: Image.cpp:1579
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
Definition: ROI.hh:443
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &hxx, Image< OutputStorageType > &hyx)
HessianSimple(bool BuildPCM=false)
void CreateFloatFilter()
create the float filter from the int filter
Definition: FilterMask.cpp:91
virtual void GetBordersValid_(int &border_x, int &border_y) const
int SimpleGreyValidFloat_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast float version for [1 0 -1]
unsigned int GetWidth() const
Definition: ImageBase.hh:312
int SimpleGreyValidInt_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast int version [1 0 -1]
simple hessian calculation hxx(x,y) = Hessian in x direction hyy(x,y) = Hessian in y direction ...
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
unsigned int GetHeight() const
Definition: ImageBase.hh:319
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same &quot;size&quot; as Image of other type
Definition: ImageBase.hh:73
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
void InitKernel_()
sets the sobel kernel for the convolution object
A filter mask (or a kernel) used for convolution.
Definition: FilterMask.hh:61
base class for simple n-&gt;3n filter implementations
Definition: FilterNTo3N.hh:43
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153