Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FilterNTo2N.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 "FilterNTo2N.hh"
27 
28 
29 using namespace BIAS;
30 
31 using namespace BIAS;
32 using namespace std;
33 
34 #include <Base/Common/BIASpragma.hh>
35 
36 template <class InputStorageType, class OutputStorageType>
39  :FilterBase<InputStorageType, OutputStorageType>()
40 {
42 }
43 
44 template <class InputStorageType, class OutputStorageType>
47  : _VecLengthType(_VecLengthType)
48 {
49 }
50 
51 template <class InputStorageType, class OutputStorageType>
53 {
54 }
55 
56 template <class InputStorageType, class OutputStorageType>
59 {
60  BIASERR("empty");
61  return -1;
62 }
63 
64 template <class InputStorageType, class OutputStorageType>
67 {
68  BIASERR("empty");
69  return -1;
70 }
71 
72 template <class InputStorageType, class OutputStorageType>
75 {
76  BIASERR("empty");
77  return -1;
78 }
79 
80 template <class InputStorageType, class OutputStorageType>
84 {
85  BIASERR("empty");
86  return -1;
87 }
88 
89 template <class InputStorageType, class OutputStorageType>
93 {
94  BIASERR("empty");
95  return -1;
96 }
97 
98 template <class InputStorageType, class OutputStorageType>
102 {
103  BIASERR("empty");
104  return -1;
105 }
106 
107 
108 ////////////////////////////////////////////////////////////////////
109 // length algorithms
110 ////////////////////////////////////////////////////////////////////
111 
112 template <class InputStorageType, class OutputStorageType>
115  const Image<OutputStorageType>& gy,
117 {
118  int res=0;
119  switch (_VecLengthType){
120  case VLT_L1:
121  res=VecLenL1(gx, gy, absg);
122  break;
123  case VLT_L2:
124  res=VecLenL2(gx, gy, absg);
125  break;
126  case VLT_max:
127  res=VecLenMax(gx, gy, absg);
128  break;
129  default:
130  BIASERR("unknown VecLengthType "<<_VecLengthType);
131  res=-1;
132  break;
133  }
134 
135  return res;
136 }
137 
138 template <class InputStorageType, class OutputStorageType>
141  const Image<OutputStorageType>& gy,
143 {
144  BIASCDOUT(D_FILTERBASE_CALLSTACK, "FilterNTo2N::VecLenL1\n");
145  unsigned htlx, htly, hbrx, hbry, vtlx, vtly, vbrx, vbry;
146  gx.GetROI()->GetCorners(htlx, htly, hbrx, hbry);
147  gy.GetROI()->GetCorners(vtlx, vtly, vbrx, vbry);
148  const int minx=(htlx<vtlx)?vtlx:htlx;
149  const int miny=(htly<vtly)?vtly:htly;
150  const int maxx=(hbrx>vbrx)?vbrx:hbrx;
151  const int maxy=(hbry>vbry)?vbry:hbry;
152 
153  register int x, y;
154  register const OutputStorageType **gxi=gx.GetImageDataArray();
155  register const OutputStorageType **gyi=gy.GetImageDataArray();
156  register OutputStorageType **absi=absg.GetImageDataArray();
157 
158  for (y=miny; y<maxy; y++){
159  for (x=minx; x<maxx; x++){
160  absi[y][x]=(OutputStorageType)(fabs((double)(gxi[y][x]))+
161  fabs((double)(gyi[y][x])));
162  }
163  }
164 
165  absg.GetROI()->SetCorners(minx, miny, maxx, maxy);
166 
167  return 0;
168 }
169 
170 template <class InputStorageType, class OutputStorageType>
173  const Image<OutputStorageType>& gy,
175 {
176  BIASCDOUT(D_FILTERBASE_CALLSTACK, "FilterNTo2N::VecLenL2\n");
177  unsigned htlx, htly, hbrx, hbry, vtlx, vtly, vbrx, vbry;
178  gx.GetROI()->GetCorners(htlx, htly, hbrx, hbry);
179  gy.GetROI()->GetCorners(vtlx, vtly, vbrx, vbry);
180  const int minx=(htlx<vtlx)?vtlx:htlx;
181  const int miny=(htly<vtly)?vtly:htly;
182  const int maxx=(hbrx>vbrx)?vbrx:hbrx;
183  const int maxy=(hbry>vbry)?vbry:hbry;
184 
185  register int x, y;
186  register const OutputStorageType **gxi=gx.GetImageDataArray();
187  register const OutputStorageType **gyi=gy.GetImageDataArray();
188  register OutputStorageType **absi=absg.GetImageDataArray();
189 
190  for (y=miny; y<maxy; y++){
191  for (x=minx; x<maxx; x++){
192  absi[y][x]=
193  (OutputStorageType)sqrt((double)(gxi[y][x])*(double)(gxi[y][x])+
194  (double)(gyi[y][x])*(double)(gyi[y][x]));
195  }
196  }
197 
198  absg.GetROI()->SetCorners(minx, miny, maxx, maxy);
199 
200  return 0;
201 }
202 
203 template <class InputStorageType, class OutputStorageType>
206  const Image<OutputStorageType>& gy,
208 {
209  BIASCDOUT(D_FILTERBASE_CALLSTACK, "FilterNTo2N::VecLenMax\n");
210  unsigned htlx, htly, hbrx, hbry, vtlx, vtly, vbrx, vbry;
211  gx.GetROI()->GetCorners(htlx, htly, hbrx, hbry);
212  gy.GetROI()->GetCorners(vtlx, vtly, vbrx, vbry);
213  const int minx=(htlx<vtlx)?vtlx:htlx;
214  const int miny=(htly<vtly)?vtly:htly;
215  const int maxx=(hbrx>vbrx)?vbrx:hbrx;
216  const int maxy=(hbry>vbry)?vbry:hbry;
217 
218  register int x, y;
219  register const OutputStorageType **gxi=gx.GetImageDataArray();
220  register const OutputStorageType **gyi=gy.GetImageDataArray();
221  register OutputStorageType **absi=absg.GetImageDataArray();
222 
223  for (y=miny; y<maxy; y++){
224  for (x=minx; x<maxx; x++){
225  absi[y][x]=(gxi[y][x]>=gyi[y][x])?(gxi[y][x]):(gyi[y][x]);
226  }
227  }
228 
229  absg.GetROI()->SetCorners(minx, miny, maxx, maxy);
230 
231  return 0;
232 }
233 
234 namespace BIAS{
235 #define FILTER_INSTANTIATION_CLASS FilterNTo2N
236 #define FILTER_INSTANTIATION_NO_UNSIGNED_OUTPUT
237 #include "Filterinst.hh"
238 }
int VecLenL2(const Image< OutputStorageType > &gx, const Image< OutputStorageType > &gy, Image< OutputStorageType > &length)
length = sqrt(gx*gx+gy*gy) destination absg must be initialized
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
dst.GetChannelCount()==2*src.GetCHannelCount()
Definition: FilterNTo2N.cpp:58
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
int VecLenL1(const Image< OutputStorageType > &gx, const Image< OutputStorageType > &gy, Image< OutputStorageType > &length)
length = | fabs(gx) + fabs(gy) | destination absg must be initialized
virtual parent class for API definition of all (future) filters
Definition: FilterBase.hh:77
int VecLen(const Image< OutputStorageType > &gx, const Image< OutputStorageType > &gy, Image< OutputStorageType > &length)
decides which vector length to use from *_VecLenthType
int VecLenMax(const Image< OutputStorageType > &gx, const Image< OutputStorageType > &gy, Image< OutputStorageType > &length)
length = max(fabs(gx),fabs(gy)) destination absg must be initialized
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Definition: FilterNTo2N.cpp:66
ROI * GetROI()
Returns a pointer to the roi object.
Definition: ImageBase.hh:615
virtual ~FilterNTo2N()
Definition: FilterNTo2N.cpp:52
int _VecLengthType
of type Gradient&lt;InputStorageType, OutputStorageType&gt;::EVecLengthType
Definition: FilterNTo2N.hh:107
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Definition: FilterNTo2N.cpp:74
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase
Definition: Image.hh:153