25 #include <Base/Common/BIASpragma.hh>
26 #include <OpenCLFramework/Filter/clfGradientGauss.hh>
27 #include <Base/Math/Vector.hh>
28 #include <Filter/FilterMask.hh>
34 template <
class InputStorageType,
class OutputStorageType>
47 template <
class InputStorageType,
class OutputStorageType>
50 delete filterMaskVert_;
53 template <
class InputStorageType,
class OutputStorageType>
56 CalculateKernels_(GaussSigma_, GaussRatio_);
57 tmpImage_->AllocateFromTemplate( *src,
false,
false);
58 program_->KernelSetArgument(
"ConvolveGradGaussXY", 0, *src );
59 program_->KernelSetArgument(
"ConvolveGradGaussXY", 1, *filterMask_ );
60 program_->KernelSetArgument(
"ConvolveGradGaussXY", 2, *filterMaskVert_ );
61 program_->KernelSetArgument(
"ConvolveGradGaussXY", 3, (
int)winSize_ );
62 program_->KernelSetArgument(
"ConvolveGradGaussXY", 4, *tmpImage_ );
66 unsigned int localx=1;
67 unsigned int localy=1;
68 if (w%8==0) localx = 8;
69 if (w%16==0) localx = 16;
70 if (h%8==0) localy = 8;
71 if (h%16==0) localy = 16;
72 context_->RunOn2DRange( *program_,
"ConvolveGradGaussXY", w, h, localx, localy);
74 program_->KernelSetArgument(
"ConvolveGradGaussXY", 0, *tmpImage_ );
75 program_->KernelSetArgument(
"ConvolveGradGaussXY", 2, *filterMask_ );
76 program_->KernelSetArgument(
"ConvolveGradGaussXY", 1, *filterMaskVert_ );
77 program_->KernelSetArgument(
"ConvolveGradGaussXY", 4, *dst );
79 context_->RunOn2DRange( *program_,
"ConvolveGradGaussXY", w, h, localx, localy);
84 template <
class InputStorageType,
class OutputStorageType>
90 filterMaskVert_->Allocate( vertSize_ *
sizeof(
float),
true,
false );
91 filterMaskVert_->WriteToBuffer( (
float*)mask );
99 template <
class InputStorageType,
class OutputStorageType>
105 template <
class InputStorageType,
class OutputStorageType>
108 if (LastSigma_ == GaussSigma_ && LastRatio_ == GaussRatio_)
return;
109 LastSigma_ = GaussSigma_;
110 LastRatio_ = GaussRatio_;
111 const int hws=(int)(floor(sqrt(-2.0*Sigma*Sigma*log(Ratio))));
112 const int size=(hws<<1)+1;
116 double fac=1.0/(2.0*Sigma*Sigma);
118 double sum=0.0, dsum=0.0;
123 for (i=0; i<=hws; i++){
126 g=expf((
float)(-(
double)(i*i)*fac));
127 V[ip] = V[im] = (float) g;
133 dsum+=fabs(2.0*
double(i)*g);
141 for (i=0; i<=hws; i++){
144 H[ip] *= (float)dsum;
145 H[im] *= (float)dsum;
146 V[ip] = V[im] = V[im]*(float)sum;
151 SetFilterHoriz_(size, H.GetData());
152 SetFilterVert_(size, V.
GetData());
int Filter(clfImage2D *src, clfImage2D *dst)
clfBuffer * CreateBuffer()
create buffer object
void GetImageDim(unsigned int &width, unsigned int &height) const
clfGradientGauss(clfContext *ctx)
int SetFilterHoriz_(unsigned int size, const float *mask)
const std::string & GetDetailedString() const
detailed combination of all info available
int SetFilterVert_(unsigned int size, const float *mask)
int SetFilter1D_(unsigned int size, const float *mask)
clf Exception wrapper, is thrown in case of most clf errors
T * GetData() const
get the pointer to the data array of the vector (for faster direct memory access) ...
void AddKernel(std::string kernelname)
adds a kernel to the program.
virtual ~clfGradientGauss()
A filter mask (or a kernel) used for convolution.
virtual void CalculateKernels_(double Sigma, double Ratio)
calculates the kernel