26 #include "GradientGaussAsymmetric.hh"
35 template <
class InputStorageType,
class OutputStorageType>
41 template <
class InputStorageType,
class OutputStorageType>
46 template <
class InputStorageType,
class OutputStorageType>
51 template <
class InputStorageType,
class OutputStorageType>
56 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, gx, gy)\n");
58 if ((fabs(this->_GradGaussSigma-this->_LastSigma)>=DBL_EPSILON) ||
59 (fabs(this->_GradGaussRatio-this->_LastRatio)>=DBL_EPSILON)){
60 _CalculateKernels(this->_GradGaussSigma, this->_GradGaussRatio);
71 if (this->_Conv.Filter(src, gx)!=0) {
72 BIASERR(
"Error in gradient x computation...");
76 this->_Conv.GetKernel(f);
78 this->_Conv.SetKernel(f);
79 int res = this->_Conv.Filter(src, gy);
81 this->_Conv.SetKernel(f);
85 template <
class InputStorageType,
class OutputStorageType>
89 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, dst)\n");
92 int res = Filter(src, grad, gy);
98 template <
class InputStorageType,
class OutputStorageType>
105 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"GradientGauss::Filter(src, gx, gy, abs)\n");
106 if ((fabs(this->_GradGaussSigma-this->_LastSigma)>=DBL_EPSILON) ||
107 (fabs(this->_GradGaussRatio-this->_LastRatio)>=DBL_EPSILON)){
108 _CalculateKernels(this->_GradGaussSigma, this->_GradGaussRatio);
116 res = Filter(src, gx, gy);
117 unsigned htlx, htly, hbrx, hbry, vtlx, vtly, vbrx, vbry;
120 const int minx=(htlx<vtlx)?vtlx:htlx;
121 const int miny=(htly<vtly)?vtly:htly;
122 const int maxx=(hbrx>vbrx)?vbrx:hbrx;
123 const int maxy=(hbry>vbry)?vbry:hbry;
131 for (y=miny; y<maxy; y++){
132 for (x=minx; x<maxx; x++){
135 absi[y][x]=(OutputStorageType) sqrt((
double)(mgx)*(
double)(mgx)+
136 (
double)(mgy)*(
double)(mgy));
142 return (res==0 && absres==0)?0:-1;
147 template <
class InputStorageType,
class OutputStorageType>
155 const double inv_max_gauss_deriv=1.0/(Sigma*expf(-0.5f));
156 BIASCDOUT(D_GRADGAUSS_KERNEL,
"max_gauss_deriv = "
157 <<1.0/inv_max_gauss_deriv<<endl);
158 const double fac=1.0/(2.0*Sigma*Sigma);
159 const int vhws=(int)(floor(sqrt(-2.0*Sigma*Sigma*log(Ratio))));
161 for (k=vhws; k*expf((
float)(-k*k*fac))*(float)inv_max_gauss_deriv>=Ratio; k++);
163 const int vsize=(vhws<<1)+1;
164 const int hsize=(hhws<<1)+1;
168 BIASCDOUT(D_GRADGAUSS_KERNEL,
"Sigma = "<<Sigma<<
"\tRatio = "<<Ratio<<endl);
169 BIASCDOUT(D_GRADGAUSS_KERNEL,
"vsize = "<<vsize<<
"\tvhws = "<<vhws<<endl);
170 BIASCDOUT(D_GRADGAUSS_KERNEL,
"hsize = "<<hsize<<
"\thhws = "<<hhws<<endl);
174 double sum=0.0, dsum=0.0;
176 for (i=0; i<=vhws; i++){
179 g=expf((
float)(-(
double)(i*i)*fac));
180 V[ip] = V[im] = (FM_FLOAT)g;
185 H[ip] = (FM_FLOAT)-g;
186 dsum += fabs(2.0*
double(i)*g);
189 for (i=vhws+1; i<=hhws; i++){
192 g=double(i)*expf((
float)(-(
double)(i*i)*fac));
195 dsum+=fabs(2.0*
double(i)*g);
206 for (i=0; i<=vhws; i++){
211 V[ip] = V[im] = V[im]*(float)sum;
213 for (i=vhws+1; i<=hhws; i++){
216 H[ip] *= (float)dsum;
217 H[im] *= (float)dsum;
219 this->_LastSigma=Sigma;
220 this->_LastRatio=Ratio;
224 sizeof(CONV_INT)*8-1);
226 this->_Conv.SetKernel(F);
230 for (i=-hhws; i<=hhws; i++){
232 BIASCDOUT(D_GRADGAUSS_KERNEL,H[i+hhws]<<
" ");
234 BIASCDOUT(D_GRADGAUSS_KERNEL,
" sum = "<<sum<<endl);
235 for (i=-vhws; i<=vhws; i++){
237 BIASCDOUT(D_GRADGAUSS_KERNEL, V[i+vhws]<<
" ");
239 BIASCDOUT(D_GRADGAUSS_KERNEL,
" sum = "<<dsum<<endl);
244 fprintf(stdout,
"gauss: \n");
245 for (i=-hhws; i<=hhws; i++){
246 fprintf(stdout,
"%f ",H[i+hhws]);
248 fprintf(stdout,
"\n");
249 fprintf(stdout,
"gaussderiv: \n");
250 for (i=-vhws; i<=vhws; i++){
251 fprintf(stdout,
"%f ",V[i+vhws]);
253 fprintf(stdout,
"\n");
262 #define FILTER_INSTANTIATION_CLASS GradientGaussAsymmetric
263 #define FILTER_INSTANTIATION_NO_UNSIGNED_OUTPUT
264 #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
virtual ~GradientGaussAsymmetric()
void _CalculateKernels(double Sigma, double Ratio)
Fills _HVec with gaussian function and _VVec with derivative of gaussian function with standard devia...
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
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy
void Transpose()
transposes the kernel (and adapts all dependent data)
GradientGaussAsymmetric()
int AppendChannel(Image< StorageType > &img)
unsigned int GetWidth() const
ROI * GetROI()
Returns a pointer to the roi object.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() 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
gradient calculation with separated gauss masks
A filter mask (or a kernel) used for convolution.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase