Rev Author Line No. Line
178 kaklik 1 #ifndef IMAGE_OP_H
2 #define IMAGE_OP_H
3  
4 #include "image.h"
5 #include "multi_array_op.h"
6  
7 /** @addtogroup arrayOp
8 @{ */
9 /** @page imageOperators Operators for mimas::image.
10 Element-wise operations for 2-dimensional images are implemented using the
11 @ref arrayOperators "operators for boost::multiarray".
12  
13 Functionality, which is specifically related to two-dimensional images,
14 is implemented for \c mimas::image.
15  
16 Algorithms, which can also be applied to n-dimensional arrays, are
17 implemented for \c boost::multi_array. Corresponding wrappers for
18 forwarding the calls are implemented for \c mimas::image.
19  
20 @author Jan Wedekind <jan@wedesoft.de>
21 @date Mon Jun 13 17:19:18 UTC 2005
22 @todo Add documentation of all available image-operators. */
23  
24 namespace mimas {
25  
26 ///
27 template<
28 typename T, class F
29 >
30 image_ref< T > &image_apply( image_ref< T > &_img, F f )
31 {
32 if ( _img.initialised() ) {
33 boost::multi_array_ref< T, 2 > data( _img.rawData(),
34 boost::extents[ _img.getHeight() ]
35 [ _img.getWidth() ] );
36 multi_apply( data, f );
37 };
38 return _img;
39 }
40  
41 ///
42 template<
43 typename T1, typename T2, class F,
44 typename T2Ptr
45 >
46 image_ref< T1 > &image_apply( image_ref< T1 > &a,
47 const const_image_ref< T2, T2Ptr > &b, F f )
48 {
49 if ( a.initialised() && b.initialised() ) {
50 boost::multi_array_ref< T1, 2 >
51 da( a.rawData(), boost::extents[ a.getHeight() ][ a.getWidth() ] );
52 boost::const_multi_array_ref< T2, 2 >
53 db( b.rawData(), boost::extents[ b.getHeight() ][ b.getWidth() ] );
54 multi_apply( da, db, f );
55 };
56 return a;
57 }
58  
59 ///
60 template<
61 typename T1, typename T2, typename T3, class F,
62 typename T2Ptr, typename T3Ptr
63 >
64 image_ref< T1 > &image_apply( image_ref< T1 > &a,
65 const const_image_ref< T2, T2Ptr > &b,
66 const const_image_ref< T3, T3Ptr > &c, F f )
67 {
68 if ( a.initialised() && b.initialised() && c.initialised() ) {
69 boost::multi_array_ref< T1, 2 >
70 da( a.rawData(), boost::extents[ a.getHeight() ][ a.getWidth() ] );
71 boost::const_multi_array_ref< T2, 2 >
72 db( b.rawData(), boost::extents[ b.getHeight() ][ b.getWidth() ] );
73 boost::const_multi_array_ref< T3, 2 >
74 dc( c.rawData(), boost::extents[ c.getHeight() ][ c.getWidth() ] );
75 multi_apply( da, db, dc, f );
76 };
77 return a;
78 }
79  
80 template<
81 typename T1, typename T2, class F,
82 typename T2Ptr
83 >
84 image< T1 > image_func( const const_image_ref< T2, T2Ptr > &a, F f )
85 {
86 image< T1 > retVal; retVal.init( a.getWidth(), a.getHeight() );
87 image_apply( retVal, a, _multi_help1< T1, T2, F >( f ) );
88 return retVal;
89 }
90  
91 template<
92 typename T1, typename T2, typename T3, class F,
93 typename T2Ptr, typename T3Ptr
94 >
95 image< T1 > image_func( const const_image_ref< T2, T2Ptr > &a,
96 const const_image_ref< T3, T3Ptr > &b,
97 F f )
98 {
99 image< T1 > retVal; retVal.init( a.getWidth(), a.getHeight() );
100 image_apply( retVal, a, b, _multi_help2< T1, T2, T3, F >( f ) );
101 return retVal;
102 }
103  
104 };
105 ///@}
106  
107 #define __MIMASINTERNALIMAGEFUNC operator*=
108 #define __MIMASEXTERNALIMAGEFUNC operator*
109 #define __MIMASFUNCTIONOBJECT std::multiplies
110 #include "image_op_help.h"
111  
112 #define __MIMASINTERNALIMAGEFUNC operator/=
113 #define __MIMASEXTERNALIMAGEFUNC operator/
114 #define __MIMASFUNCTIONOBJECT std::divides
115 #include "image_op_help.h"
116  
117 #define __MIMASINTERNALIMAGEFUNC operator+=
118 #define __MIMASEXTERNALIMAGEFUNC operator+
119 #define __MIMASFUNCTIONOBJECT std::plus
120 #include "image_op_help.h"
121  
122 #define __MIMASINTERNALIMAGEFUNC operator-=
123 #define __MIMASEXTERNALIMAGEFUNC operator-
124 #define __MIMASFUNCTIONOBJECT std::minus
125 #include "image_op_help.h"
126  
127 #define __MIMASEXTERNALIMAGEFUNC absolute
128 #define __MIMASINTERNALIMAGEFUNC absoluteIt
129 #define __MIMASFUNCTIONOBJECT _abs
130 #include "image_op_help2.h"
131  
132 #define __MIMASEXTERNALIMAGEFUNC conj
133 #define __MIMASINTERNALIMAGEFUNC conjIt
134 #define __MIMASFUNCTIONOBJECT _conj
135 #include "image_op_help2.h"
136  
137 #define __MIMASEXTERNALIMAGEFUNC sqr
138 #define __MIMASINTERNALIMAGEFUNC sqrIt
139 #define __MIMASFUNCTIONOBJECT _sqr
140 #include "image_op_help2.h"
141  
142 #define __MIMASEXTERNALIMAGEFUNC logarithm
143 #define __MIMASINTERNALIMAGEFUNC logarithmIt
144 #define __MIMASFUNCTIONOBJECT _log
145 #include "image_op_help2.h"
146  
147 #define __MIMASEXTERNALIMAGEFUNC squareRoot
148 #define __MIMASINTERNALIMAGEFUNC squareRootIt
149 #define __MIMASFUNCTIONOBJECT _sqrt
150 #include "image_op_help2.h"
151  
152 #define __MIMASEXTERNALIMAGEFUNC sumSquares
153 #define __MIMASFUNCTIONOBJECT _sumsquares
154 #include "image_op_help3.h"
155  
156 #define __MIMASEXTERNALIMAGEFUNC orientation
157 #define __MIMASFUNCTIONOBJECT _orientation
158 #include "image_op_help3.h"
159  
160 namespace mimas {
161  
162 /** @addtogroup arrayOp
163 @{ */
164 ///
165 template <
166 typename T1, typename T2, typename T2Ptr
167 >
168 image< T1 > norm( const const_image_ref< T2, T2Ptr > &a )
169 {
170 return image_func< T1 >( a, _norm< T1, T2 >() );
171 }
172  
173 ///
174 template <
175 typename T1, typename T2
176 >
177 image< T1 > arg( const image< T2 > &a )
178 {
179 return image_func< T1 >( a, _arg< T1, T2 >() );
180 }
181  
182 ///
183 template <
184 typename T
185 >
186 image< int > fastSqr( const image< T > &a )
187 {
188 return image_func< int >( a, _fastsqr< T >() );
189 };
190  
191 }
192  
193 #endif