RecFilter
iir_coeff.h
Go to the documentation of this file.
1 #ifndef _IIR_FILTER_COEFFICIENTS_H_
2 #define _IIR_FILTER_COEFFICIENTS_H_
3 
4 #include <cmath>
5 #include <complex>
6 #include <iostream>
7 #include <Halide.h>
8 
9 /**
10  * Compute the coefficients of a higher order filter that is equivalent
11  * to two cascaded lower order filters of given coefficients
12  *
13  * \todo This function is only partially tested and may be unstable
14  *
15  * \param[in] a coefficients of first lower order filter
16  * \param[in] b coefficients of second lower order filter
17  * \returns coefficients of higher order filter
18  */
19 std::vector<float> overlap_feedback_coeff(std::vector<float> a, std::vector<float> b);
20 
21 /**
22  * Feed forward and feedback coefficients for computing n integrals of image,
23  * single intergal is summed area table and multiple integrals are multiple
24  * applications of summed area table
25  *
26  * \param[in] iterations number of integrals
27  * \returns coeff of IIR filter that computes multiple integrals
28  */
29 std::vector<float> integral_image_coeff(int iterations);
30 
31 
32 
33 /**@name Compute the Gaussian, derivative of Gaussian and integral of Gaussian
34  * @param[in] x input (float or Halide::Expr)
35  * @param[in] mu mean of the Gaussian function
36  * @param[in] sigma sigma support of the true Gaussian filter
37  */
38 // @ {
39 float gaussian (float x, float mu, float sigma);
40 float gaussDerivative(float x, float mu, float sigma);
41 float gaussIntegral (float x, float mu, float sigma);
42 
43 Halide::Expr gaussian (Halide::Expr x, float mu, float sigma);
44 Halide::Expr gaussDerivative(Halide::Expr x, float mu, float sigma);
45 Halide::Expr gaussIntegral (Halide::Expr x, float mu, float sigma);
46 // @}
47 
48 
49 /**
50  * @brief Wrapper to compute third order recursive filter weights for Gaussian blur.
51  * Third order filter can be approximated by cascaded first and second order filters
52  * @param[in] order order of recursive filter for approximation
53  * @param[in] sigma sigma of Gaussian filter
54  *
55  * @return vector with feedforward coeff as first element and rest feedback coeff
56  */
57 std::vector<float> gaussian_weights(float sigma, int order);
58 
59 /**
60  * @brief Compute the size of a box filter that approximates a Gaussian
61  *
62  * Source: "Efficient Approximation of Gaussian Filters"
63  * Rau and McClellan, IEEE Trans. on Signal Processing 1997
64  * http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=554310
65  *
66  * @param[in] iterations number of repeated applications of box filter
67  * @param[in] sigma sigma support of the true Gaussian filter
68  * @return box filter width
69  */
70 int gaussian_box_filter(int iterations, float sigma);
71 
72 
73 /** @brief Apply Gaussian filter on an input image
74  *
75  * @param[in] in input single channel image
76  * @param[in] sigma sigma support of the true Gaussian filter
77  * @return filtered image
78  */
79 template <typename T>
80 Halide::Image<T> reference_gaussian(Halide::Image<T> in, T sigma) {
81  int width = in.width();
82  int height= in.height();
83  Halide::Image<T> ref(width,height);
84  for (int y=0; y<height; y++) {
85  for (int x=0; x<width; x++) {
86  float a = 0.0;
87  float w = 0.0;
88  for (int j=0; j<height; j++) {
89  for (int i=0; i<width; i++) {
90  float d = (x-i)*(x-i) + (y-j)*(y-j);
91  float g = gaussian(std::sqrt(d), 0.0, sigma);
92  a += g * in(i,j);
93  w += g;
94  }
95  }
96  ref(x,y) = a/w;
97  }
98  }
99  return ref;
100 }
101 
102 #endif // _IIR_FILTER_COEFFICIENTS_H_
std::vector< float > gaussian_weights(float sigma, int order)
Wrapper to compute third order recursive filter weights for Gaussian blur.
int gaussian_box_filter(int iterations, float sigma)
Compute the size of a box filter that approximates a Gaussian.
float gaussian(float x, float mu, float sigma)
float gaussIntegral(float x, float mu, float sigma)
Halide::Image< T > reference_gaussian(Halide::Image< T > in, T sigma)
Apply Gaussian filter on an input image.
Definition: iir_coeff.h:80
std::vector< float > integral_image_coeff(int iterations)
Feed forward and feedback coefficients for computing n integrals of image, single intergal is summed ...
float gaussDerivative(float x, float mu, float sigma)
std::vector< float > overlap_feedback_coeff(std::vector< float > a, std::vector< float > b)
Compute the coefficients of a higher order filter that is equivalent to two cascaded lower order filt...