26 #include "GradientGauss.hh"
27 #include "Convolution.hh"
36 template <
class StorageType,
class OutputStorageType>
45 template <
class StorageType,
class OutputStorageType>
48 : _GradGaussSigma(other._GradGaussSigma),
49 _GradGaussRatio(other._GradGaussRatio),
50 _LastSigma(other._LastSigma),
51 _LastRatio(other._LastRatio),
56 template <
class InputStorageType,
class OutputStorageType>
60 template <
class InputStorageType,
class OutputStorageType>
64 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, dst)\n");
67 int res = Filter(src, grad, gy);
72 template <
class InputStorageType,
class OutputStorageType>
77 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, gx, gy)\n");
81 if ((fabs(_GradGaussSigma-_LastSigma)>=DBL_EPSILON) ||
82 (fabs(_GradGaussRatio-_LastRatio)>=DBL_EPSILON)){
83 _CalculateKernels(_GradGaussSigma, _GradGaussRatio);
94 if (_Conv.Filter(src, gx)!=0) {
95 BIASERR(
"Error in gradient x computation...");
102 int res = _Conv.Filter(src, gy);
108 template <
class InputStorageType,
class OutputStorageType>
113 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, gx, gy, absg)\n");
119 int res = Filter(src,gx,gy);
120 int absres = this->VecLen(gx, gy, absg);
121 return (res==0 && absres ==0)?0:-1;
124 template <
class InputStorageType,
class OutputStorageType>
128 const int hws=(int)(floor(sqrt(-2.0*Sigma*Sigma*log(Ratio))));
129 const int size=(hws<<1)+1;
132 BIASCDOUT(D_GRADGAUSS_KERNEL,
"Sigma = "<<Sigma<<
"\tRatio = "<<Ratio<<endl);
133 BIASCDOUT(D_GRADGAUSS_KERNEL,
"size = "<<size<<
"\thws = "<<hws<<endl);
136 double fac=1.0/(2.0*Sigma*Sigma);
138 double sum=0.0, dsum=0.0;
143 for (i=0; i<=hws; i++){
146 g=expf((
float)(-(
double)(i*i)*fac));
147 V[ip] = V[im] = (FM_FLOAT) g;
148 BIASCDOUT(D_GRADGAUSS_KERNEL, i<<
" v:"<<V[im]<<
" "<<endl);
152 H[im] = (FM_FLOAT) g;
153 H[ip] = (FM_FLOAT) -g;
154 dsum+=fabs(2.0*
double(i)*g);
155 BIASCDOUT(D_GRADGAUSS_KERNEL, i<<
" h:"<< H[im]<<
" "<<endl);
159 BIASCDOUT(D_GRADGAUSS_KERNEL,
"sum = "<<sum<<
"\tdsum = "<<dsum<<endl);
164 BIASCDOUT(D_GRADGAUSS_KERNEL,
"sum = "<<sum<<
"\tdsum = "<<dsum<<endl);
165 for (i=0; i<=hws; i++){
168 H[ip] *= (FM_FLOAT)dsum;
169 H[im] *= (FM_FLOAT)dsum;
170 V[ip] = V[im] = V[im]*(FM_FLOAT)sum;
171 BIASCDOUT(D_GRADGAUSS_KERNEL,
"h:"<< H[im]<<
" "<<endl);
176 sizeof(CONV_INT)*8-1);
186 for (i=-hws; i<=hws; i++){
188 BIASCDOUT(D_GRADGAUSS_KERNEL, H[i+hws]<<
" ");
190 BIASCDOUT(D_GRADGAUSS_KERNEL,
" sum = "<<sum<<endl);
191 for (i=-hws; i<=hws; i++){
193 BIASCDOUT(D_GRADGAUSS_KERNEL, V[i+hws]<<
" ");
195 BIASCDOUT(D_GRADGAUSS_KERNEL,
" sum = "<<dsum<<endl);
201 template <
class InputStorageType,
class OutputStorageType>
205 _Conv.GetBorders(border_x, border_y);
213 #define FILTER_INSTANTIATION_CLASS GradientGauss
214 #define FILTER_INSTANTIATION_NO_UNSIGNED_OUTPUT
215 #include "Filterinst.hh"
void Release()
reimplemented from ImageBase
gradient calculation with separated gauss masks
void CreateIntFilter(int rshift, int rshifth, int rshiftv)
create the int filter from the float filter
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void Transpose()
transposes the kernel (and adapts all dependent data)
int AppendChannel(Image< StorageType > &img)
unsigned int GetWidth() const
void _CalculateKernels(double Sigma, double Ratio)
Fills _HVec with gaussian function and _VVec with derivative of gaussian function with standard devia...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containig gx and gy
unsigned int GetHeight() const
virtual void GetBordersValid_(int &border_x, int &border_y) const
int ComputeIntPrecisionBits(int NumberOfBitsInInputData, int NumberOfBitsInTempData)
compute the number of shiftable bits for int-from-float mask
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
A filter mask (or a kernel) used for convolution.