26 #include "GradientSimple.hh"
27 #include "FilterMask.hh"
34 #define POLAR_TABLE_OFFSET 128
35 #define POLAR_TABLE_SIZE 257
39 template <
class InputStorageType,
class OutputStorageType>
void
47 if (useDirectNeighbors_) {
57 FilterMask f(h, v, useDirectNeighbors_?0:1, 0);
62 template <
class InputStorageType,
class OutputStorageType>
65 :
FilterNTo2N<InputStorageType, OutputStorageType>() ,
66 pRadius_(NULL), pAngle_(NULL), useDirectNeighbors_(false)
72 template <
class InputStorageType,
class OutputStorageType>
76 useDirectNeighbors_(other.useDirectNeighbors_)
81 template <
class InputStorageType,
class OutputStorageType>
85 if (pRadius_ != NULL) {
86 pRadius_ -= POLAR_TABLE_OFFSET;
87 for (
int i=0; i<POLAR_TABLE_SIZE; i++)
88 delete [] (pRadius_[i]-POLAR_TABLE_OFFSET);
92 if (pAngle_ != NULL) {
93 pAngle_ -= POLAR_TABLE_OFFSET;
94 for (
int i=0; i<POLAR_TABLE_SIZE; i++)
95 delete [] (pAngle_[i]-POLAR_TABLE_OFFSET);
102 template <
class InputStorageType,
class OutputStorageType>
106 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::Filter(src, dst)\n");
108 int res=Filter(src, grad, gy);
113 template <
class InputStorageType,
class OutputStorageType>
118 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::Filter(src, gx, gy)\n");
130 if (_Conv.CalculationInFloat()){
131 if (useDirectNeighbors_)
132 res = DirectNeighborsGreyValidFloat_(src, gx, gy);
134 res = SimpleGreyValidFloat_(src, gx, gy);
136 if (useDirectNeighbors_)
137 res = DirectNeighborsGreyValidInt_(src, gx, gy);
139 res = SimpleGreyValidInt_(src, gx, gy);
143 BIASERR(
"not for multiple channel images");
149 template <
class InputStorageType,
class OutputStorageType>
154 BIASCDOUT(D_FILTERBASE_CALLSTACK,
155 "GradientSimple::Filter(src, gx, gy, abs)\n");
162 res = Filter(src, gx, gy);
164 absres = this->VecLen(gx, gy, absg);
166 return (res==0 && absres==0)?0:-1;
172 template <
class InputStorageType,
class OutputStorageType>
178 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::SimpleGreyValidFloat_\n");
182 const int width=(int)src.
GetWidth();
183 const int nwidth = - width;
190 BIASASSERT(_Conv.CalculationInFloat());
193 int minx, miny, maxx, maxy;
198 const InputStorageType *ph;
201 OutputStorageType *pgx, *pgy, *end2, *lend2;
204 int step=width-maxx+minx;
206 offset=minx+1+(miny+1)*width;
211 end2=gx+maxx+width*(maxy-2)-1;
212 lend2=gx+maxx+width*(miny+1)-1;
215 *pgx++ = (OutputStorageType)(ph[1] - ph[-1])/
216 (OutputStorageType)2;
217 *pgy++ = (OutputStorageType)(ph[width] - ph[nwidth])/
218 (OutputStorageType)2;
230 template <
class InputStorageType,
class OutputStorageType>
236 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::SimpleGreyValidInt_\n");
240 const int width=(int)src.
GetWidth();
241 const int nwidth = - width;
248 BIASASSERT(!_Conv.CalculationInFloat());
253 int minx, miny, maxx, maxy;
258 const InputStorageType *ph;
261 OutputStorageType *pgx, *pgy, *end2, *lend2;
264 int step=width-maxx+minx;
266 offset=minx+1+(miny+1)*width;
272 end2=gx+maxx+width*(maxy-2)-1;
273 lend2=gx+maxx+width*(miny+1)-1;
276 *pgx++ = (OutputStorageType)(ph[1] - ph[-1])/
277 (OutputStorageType)2;
278 *pgy++ = (OutputStorageType)(ph[width] - ph[nwidth])/
279 (OutputStorageType)2;
292 template <
class InputStorageType,
class OutputStorageType>
298 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::SimpleGreyValidFloat_\n");
302 const int width=(int)src.
GetWidth();
309 BIASASSERT(_Conv.CalculationInFloat());
312 int minx, miny, maxx, maxy;
317 const InputStorageType *ph;
320 OutputStorageType *pgx, *pgy, *end2, *lend2;
323 int step=width-maxx+minx;
325 offset=minx+1+(miny+1)*width;
330 end2=gx+maxx+width*(maxy-2)-1;
331 lend2=gx+maxx+width*(miny+1)-1;
334 *pgx++ = (OutputStorageType)(ph[1] - ph[0]);
335 *pgy++ = (OutputStorageType)(ph[width] - ph[0]);
349 template <
class InputStorageType,
class OutputStorageType>
355 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientSimple::SimpleGreyValidInt_\n");
359 const int width=(int)src.
GetWidth();
366 BIASASSERT(!_Conv.CalculationInFloat());
371 int minx, miny, maxx, maxy;
376 const InputStorageType *ph;
379 OutputStorageType *pgx, *pgy, *end2, *lend2;
382 int step=width-maxx+minx;
384 offset = minx+1+(miny+1)*width;
391 end2 = gx + maxx + width*(maxy-2)-1;
392 lend2 = gx + maxx + width*(miny+1)-1;
395 *pgx++ = (OutputStorageType)(ph[1] - ph[0]);
396 *pgy++ = (OutputStorageType)(ph[width] - ph[0]);
418 template <
class InputStorageType,
class OutputStorageType>
422 BIASASSERT(pRadius_ == NULL);
423 BIASASSERT(pAngle_ == NULL);
425 pRadius_ =
new float* [POLAR_TABLE_SIZE];
426 for (
int i=0; i<POLAR_TABLE_SIZE; i++)
427 pRadius_[i] =
new float [POLAR_TABLE_SIZE] + POLAR_TABLE_OFFSET;
428 pRadius_ += POLAR_TABLE_OFFSET;
430 pAngle_ =
new float* [POLAR_TABLE_SIZE];
431 for (
int i=0; i<POLAR_TABLE_SIZE; i++)
432 pAngle_[i] =
new float [POLAR_TABLE_SIZE] + POLAR_TABLE_OFFSET;
433 pAngle_ += POLAR_TABLE_OFFSET;
435 for (
int x=-POLAR_TABLE_OFFSET; x<=128; x++) {
436 for (
int y=-POLAR_TABLE_OFFSET; y<=128; y++) {
437 pRadius_[x][y] = sqrtf(
float(x*x+y*y));
439 pAngle_[x][y] = -atan2f(
float(y),
float(x) );
440 if (pAngle_[x][y] < 0.0f)
441 (pAngle_[x][y]) += 2.0f * (
float)M_PI;
450 if (pRadius_ == NULL) BuildPolarCoordinateMap_();
451 BIASASSERT(pRadius_ != NULL);
464 *pp++ = pAngle_[(
unsigned int)*pgx][(
unsigned int)*pgy];
465 *pm++ = pRadius_[(
unsigned int)*pgx++][(
unsigned int)*pgy++];
469 template <
class InputStorageType,
class OutputStorageType>
482 int minx, miny, maxx, maxy;
491 if ((*pp = -atan2f(
float(*pgy),
float(*pgx) ))<0.0f) {
492 *pp += float(2.0*M_PI);
495 *pm++ = sqrtf(
float(*pgx) *
float(*pgx) +
float(*pgy) *
float(*pgy));
502 template <
class InputStorageType,
class OutputStorageType>
506 _Conv.GetBorders(border_x, border_y);
512 #define FILTER_INSTANTIATION_CLASS GradientSimple
513 #define FILTER_INSTANTIATION_NO_UNSIGNED_OUTPUT
514 #include "Filterinst.hh"
void Release()
reimplemented from ImageBase
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
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...
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
int AppendChannel(Image< StorageType > &img)
base class for simple n->2n filter implementations
void PolarTransform(Image< OutputStorageType > &gx, Image< OutputStorageType > &gy, Image< float > &magnitude, Image< float > &phase)
void InitKernel_()
sets the sobel kernel for the convolution object
void CreateFloatFilter()
create the float filter from the int filter
int SimpleGreyValidInt_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast int version [1 0 -1]
GradientSimple(bool BuildPCM=false)
unsigned int GetWidth() const
simple gradient calculation gx(x,y) = I(x+1,y) - I(x-1,y) gy(x,y) = I(x,y+1) - I(x,y-1)
int DirectNeighborsGreyValidInt_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast int version [1 -1]
ROI * GetROI()
Returns a pointer to the roi object.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int SimpleGreyValidFloat_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast float version for [1 0 -1]
unsigned int GetHeight() const
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void BuildPolarCoordinateMap_()
set up pRadius and pAngle for polar coordinate transformation
virtual ~GradientSimple()
int DirectNeighborsGreyValidFloat_(const Image< InputStorageType > &src, Image< OutputStorageType > &gWE, Image< OutputStorageType > &gNS)
loop unrolled fast float version [1 -1]
virtual void GetBordersValid_(int &border_x, int &border_y) const
unsigned long int GetPixelCount() const
returns number of pixels in image
A filter mask (or a kernel) used for convolution.
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy