1 #ifndef TIL_RECURSIVE_FILTER4_H 2 #define TIL_RECURSIVE_FILTER4_H 22 template <
typename TT,
int direction >
45 const T*
getMI()
const {
return m_mi; }
47 const T*
getMO()
const {
return m_mo; }
52 void setFilter(T mi0, T mi1, T mi2, T mi3, T mo0, T mo1, T mo2, T mo3)
69 void setFilterFromFormula(T a0, T a1, T c0, T c1, T w0, T w1, T b0, T b1, T sigma);
79 norm = 2.0*norm - m_mi[0];
93 void apply(
const std::vector<T> &in, std::vector<T> &out)
const;
100 T borderFactor()
const {
return 101 ( m_mi[0] + m_mi[1] + m_mi[2] + m_mi[3]) /
102 (1 + m_mo[0] + m_mo[1] + m_mo[2] + m_mo[3]); }
104 T
apply(T in0, T in1, T in2, T in3, T out0, T out1, T out2, T out3)
const 134 template <
typename TT,
int direction >
137 typename std::vector<T>::const_iterator pIn;
138 typename std::vector<T>::iterator pOut;
140 size_t length = in.size();
141 assert(in.size() == out.size());
148 else if (direction == -1)
150 pIn = in.begin() + length - 1;
151 pOut = out.begin() + length - 1;
154 size_t count = length;
156 T x0, x1 = 0, x2 = 0, x3 = 0;
157 T y0 = 0, y1 = 0, y2 = 0, y3 = 0;
161 switch (m_boundaryConditions)
165 y0 = y1 = y2 = y3 = 0;
169 y0 = y1 = y2 = y3 = *pIn * this->borderFactor();
175 *pOut += y3 = this->
apply(x0, x1, x2, x3, y0, y1, y2, y3);
176 if (--count == 0)
break;
181 *pOut += y2 = this->
apply(x3, x0, x1, x2, y3, y0, y1, y2);
182 if (--count == 0)
break;
187 *pOut += y1 = this->
apply(x2, x3, x0, x1, y2, y3, y0, y1);
188 if (--count == 0)
break;
193 *pOut += y0 = this->
apply(x1, x2, x3, x0, y1, y2, y3, y0);
194 if (--count == 0)
break;
200 template <
typename TT,
int direction >
201 void RecursiveFilter<TT,direction,4>::setFilterFromFormula(
T a0,
T a1,
T c0,
T c1,
T w0,
T w1,
T b0,
T b1,
T sigma)
206 T cw0 = cos(w0/sigma);
207 T cw1 = cos(w1/sigma);
208 T sw0 = sin(w0/sigma);
209 T sw1 = sin(w1/sigma);
211 T eb0 = exp(-b0/sigma);
212 T eb1 = exp(-b1/sigma);
213 T e2b0 = exp(-2.0*b0/sigma);
214 T e2b1 = exp(-2.0*b1/sigma);
215 T eb0b1 = exp(-(b0+b1)/sigma);
216 T e2b0b1 = exp(-(2.0*b0+b1)/sigma);
217 T eb02b1 = exp(-(b0+2.0*b1)/sigma);
231 2.0 * eb0b1 * ((a0+c0)*cw0*cw1 - a1*sw0*cw1 - c1*sw1*cw0)
232 + c0 * e2b0 + a0 * e2b1;
233 m_mi[3] = e2b0b1 * (c1*sw1 - c0*cw1) + eb02b1 * (a1*sw0 - a0*cw0);
238 m_mo[0] = -2.0*(eb1*cw1 + eb0*cw0);
239 m_mo[1] = 4*cw1*cw0*eb0b1 + e2b0 + e2b1;
240 m_mo[2] = -2.0*(cw0*eb02b1 + cw1*e2b0b1);
241 m_mo[3] = exp(-2.0*(b0+b1)/sigma);
INLINE void apply(const Affine< T1 > &a, const numeric_array< T2, 3 > &in, numeric_array< typename combine< T1, T2 >::type, 3 > &out)
INLINE double norm(const T &a, const T &b)
< Euclidean norm of 2D vector (a, b)
Belongs to package Box Do not include directly, include til/Box.h instead.
General macros, definitions and functions.
RecursiveFilter< TT, direction, 4 > Self
void setFilter(T mi0, T mi1, T mi2, T mi3, T mo0, T mo1, T mo2, T mo3)
void setBoundaryConditions(BoundaryConditions bc)