Rev Author Line No. Line
178 kaklik 1 #ifndef GAUSS_H
2 #define GAUSS_H
3  
4 #include <boost/multi_array.hpp>
5 #include <cassert>
6 #include <cmath>
7 #include <deque>
8 #include "image.h"
9 #include "image_conv.h"
10 #include "image_op.h"
11  
12 namespace mimas {
13  
14 /** @defgroup gauss Gaussian blur and Gauss gradient
15 Methods for blurring images with a gauss-bell and gauss-gradient.
16 The filter-parameter \f$\sigma\f$ can be choosen and the size of the filter
17 is computed by choosing an upper bound for the approximation-error.
18  
19 The following example demonstrates how to blur an image:
20 \include gauss_tool/main.cc
21  
22 @author Stuart Meikle (stu@stumeikle.org)
23 @author Jan Wedekind (jan@wedesoft.de)
24 @date Fri Apr 07 18:52:00 2006
25 @{ */
26 /** Compute gauss-bell.
27 The values of the cells are computed by using differences of the integral
28 of the gauss-function:
29 \f$\displaystyle\int_{-r}^{+r}{\frac{1}{\sqrt{2\,\pi}\,\sigma}\,e^{-\displaystyle\frac{x^2}{2\,\sigma^2}}\,\mathrm{d}x}\ =\ \mathrm{erf}(\displaystyle\frac{r}{\sqrt{2}\,\sigma})\f$
30  
31 The coefficients are normalised afterwards such that the sum of all
32 elements of the filter is \f$1\f$.
33 @param sigma Standard deviation of gauss-distribution.
34 @param maxError Maximum error boundary
35 (relative to range of pixel-values).
36 @see gaussBlur */
37 template< typename T >
38 std::deque< T > gaussBlurFilter( T sigma, T maxError = (T)( 1.0 / 256.0 ) );
39  
40 /** Blur 2-D array.
41 Perform gaussian blur on 2-D array.
42 @param x Input array.
43 @param sigma Standard deviation.
44 @param maxError Maximum error boundary (relative to range of pixel-values).
45 @see gaussBlurFilter */
46 template< typename T >
47 boost::multi_array< T, 2 > gaussBlur
48 ( const boost::const_multi_array_ref< T, 2 > &x, T sigma, T maxError );
49  
50 /** Blur image.
51 Perform gaussian blur on 2-D image.
52 @param x Input image.
53 @param sigma Standard deviation.
54 @param maxError Maximum error boundary (relative to range of pixel-values).
55 @see gaussBlurFilter */
56 template< typename T >
57 image< T > gaussBlur( const image< T > &x, T sigma,
58 T maxError = (T)( 1.0 / 256.0 ) )
59 {
60 boost::const_multi_array_ref< T, 2 > data
61 ( x.rawData(), boost::extents[ x.getHeight() ][ x.getWidth() ] );
62 image< T > retVal; retVal.init( x.getWidth(), x.getHeight() );
63 boost::multi_array_ref< T, 2 >
64 ( retVal.rawData(),
65 boost::extents[ retVal.getHeight() ][ retVal.getWidth() ] ) =
66 gaussBlur< T >( data, sigma, maxError );
67 return retVal;
68 }
69  
70 /** Compute gauss-gradient.
71 The values of the cells are computed by using differences of the
72 integral (the gauss-function):
73 \f$\frac{1}{\sqrt{2\,\pi}\,\sigma}\,e^{-\displaystyle\frac{x^2}{2\,\sigma^2}}\,\mathrm{d}x\big\|_r^\infty\f$
74  
75 The coefficients are normalised afterwards such that the sum of the square
76 of all elements of the filter is \f$1\f$.
77 @param sigma Standard deviation of gauss-distribution.
78 @param maxError Maximum error boundary
79 (relative to range of pixel-values).
80 @see gaussBlur */
81 template< typename T >
82 std::deque< T > gaussGradientFilter( T sigma,
83 T maxError = (T)( 1.0 / 256.0 ) );
84  
85 /** Take x-gradient of 2-D array.
86 Compute gauss-gradient of 2-D array in x-direction.
87 @param x Input array.
88 @param sigma Standard deviation.
89 @param maxError Maximum error boundary (relative to range of pixel-values).
90 @see gaussGradientFilter */
91 template< typename T >
92 boost::multi_array< T, 2 > gaussGradientX
93 ( const boost::const_multi_array_ref< T, 2 > &x, T sigma, T maxError );
94  
95 /** Take x-gradient of 2-D image.
96 Compute gauss-gradient of 2-D image in x-direction.
97 @param x Input image.
98 @param sigma Standard deviation.
99 @param maxError Maximum error boundary (relative to range of pixel-values).
100 @see gaussGradientFilter */
101 template< typename T >
102 image< T > gaussGradientX( const image< T > &x, T sigma,
103 T maxError = (T)( 1.0 / 256.0 ) );
104  
105 /** Take y-gradient of 2-D array.
106 Compute gauss-gradient of 2-D array in y-direction.
107 @param x Input array.
108 @param sigma Standard deviation.
109 @param maxError Maximum error boundary (relative to range of pixel-values).
110 @see gaussGradientFilter */
111 template< typename T >
112 boost::multi_array< T, 2 > gaussGradientY
113 ( const boost::const_multi_array_ref< T, 2 > &x, T sigma, T maxError );
114  
115 /** Take y-gradient of 2-D image.
116 Compute gauss-gradient of 2-D image in y-direction.
117 @param x Input image.
118 @param sigma Standard deviation.
119 @param maxError Maximum error boundary (relative to range of pixel-values).
120 @see gaussGradientFilter */
121 template< typename T >
122 image< T > gaussGradientY( const image< T > &x, T sigma,
123 T maxError = (T)( 1.0 / 256.0 ) );
124  
125 /** Square of gradient-norm.
126 Compute square of gradient-norm for 2-D image
127 @param im Input image.
128 @param sigma Standard deviation.
129 @param maxError Maximum error boundary (relative to range of pixel-values).
130 @see gaussGradientFilter */
131 template< typename T >
132 image< T > gaussGradientSqr( const image< T > &im, T sigma,
133 T maxError = (T)( 1.0 / 256.0 ) )
134 {
135 image< T >
136 gradX( gaussGradientX( im, sigma, maxError ) ),
137 gradY( gaussGradientY( im, sigma, maxError ) );
138 return sumSquares( gradX, gradY );
139 }
140  
141 /** Gradient-norm.
142 Compute gradient-norm for 2-D image
143 @param im Input image.
144 @param sigma Standard deviation.
145 @param maxError Maximum error boundary (relative to range of pixel-values).
146 @see gaussGradientFilter */
147 template< typename T >
148 image< T > gaussGradientNorm( const image< T > &im, T sigma,
149 T maxError = (T)( 1.0 / 256.0 ) )
150 {
151 return squareRoot( gaussGradientSqr( im, sigma, maxError ) );
152 }
153  
154 ///@}
155  
156 };
157  
158 #include "gauss.tcc"
159  
160 #endif