aimsalgo 6.0.0
Neuroimaging image processing
filteringfunction_element_d.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34
35#ifndef AIMS_SIGNALFILTER_FILTERINGFUNCTION_ELEMENT_D_H
36#define AIMS_SIGNALFILTER_FILTERINGFUNCTION_ELEMENT_D_H
37
38//--- aims -------------------------------------------------------------------
40#include <aims/connectivity/structuring_element.h> // aims::StructuringElement
41#include <aims/math/mathelem.h> // absdiff + all iterator methods
42//--- cartodata --------------------------------------------------------------
43#include <cartodata/volume/volumeutil_d.h>
44#include <cartodata/volume/volume.h> // carto::VolumeRef
45//--- cartobase --------------------------------------------------------------
46#include <cartobase/config/verbose.h> // carto::verbose
47#include <cartobase/smart/rcptr.h> // carto::rc_ptr
48//--- std --------------------------------------------------------------------
49#include <cmath>
50#include <map>
51#include <set>
52#include <string>
53#include <algorithm> // std::max_element
54#include <limits> // std::numeric_limits
55//----------------------------------------------------------------------------
56
57namespace aims {
58
59//============================================================================
60// ELEMENT FILTERING FUNCTIONS: FACTORY
61//============================================================================
62
63 template <typename T>
65 {
66 static bool initialized = false;
67 if( !initialized )
68 {
69 initialized = true;
70 registerFunction( "min", MinFilterFunc<T>() );
71 registerFunction( "max", MaxFilterFunc<T>() );
72 registerFunction( "med", MedianFilterFunc<T>() );
73 registerFunction( "median", MedianFilterFunc<T>() );
74 registerFunction( "notnullmedian", NotNullMedianFilterFunc<T>() );
75 registerFunction( "mea", MeanFilterFunc<T>() );
76 registerFunction( "mean", MeanFilterFunc<T>() );
77 registerFunction( "notnullmean", NotNullMeanFilterFunc<T>() );
78 registerFunction( "maj", MajorityFilterFunc<T>() );
79 registerFunction( "majority", MajorityFilterFunc<T>() );
80 registerFunction( "notnullmajority", NotNullMajorityFilterFunc<T>() );
81 registerFunction( "dif", ExtremaDifferenceFilterFunc<T>() );
82 registerFunction( "difference", ExtremaDifferenceFilterFunc<T>() );
83 registerFunction( "sum", SumFilterFunc<T>() );
84 registerFunction( "var", VarFilterFunc<T>() );
85 registerFunction( "variance", VarFilterFunc<T>() );
86 registerFunction( "sd", StDevFilterFunc<T>() );
87 }
88 }
89
90 template <typename T>
91 std::map<std::string,carto::rc_ptr<ElementFilteringFunction<T> > > &
93 {
94 static std::map<std::string,carto::rc_ptr<ElementFilteringFunction<T> > > m;
95 return m;
96 }
97
98 template <typename T>
100 const std::string & name,
101 const ElementFilteringFunction<T> & func
102 )
103 {
104 init();
106 }
107
108 template <typename T>
110 {
111 init();
112 std::set<std::string> s;
113 typename std::map<std::string,carto::rc_ptr<ElementFilteringFunction<T> > >::const_iterator i, e = _map().end();
114 for( i=_map().begin(); i!=e; ++i )
115 s.insert( i->first );
116 return( s );
117 }
118
119 template <typename T>
121 const std::string & name,
122 carto::Object options
123 )
124 {
125 init();
126 typename std::map<std::string,carto::rc_ptr<ElementFilteringFunction<T> > >::const_iterator i;
127 i = _map().find( name );
128 if( i == _map().end() )
129 return( 0 );
130 ElementFilteringFunction<T> * new_func = i->second->clone();
131 new_func->setOptions( options );
132 return new_func;
133 }
134
135//============================================================================
136// ELEMENT FILTERING FUNCTIONS: DERIVED CLASSES
137//============================================================================
138 //--------------------------------------------------------------------------
139 // MaxFilterFunc
140 //--------------------------------------------------------------------------
141 template <class T> inline
142 T MaxFilterFunc<T>::execute( const carto::VolumeRef<T> & volume ) const
143 {
144 return carto::VolumeUtil<T>::max(volume);
145 }
146
147 template <class T> inline
148 T MaxFilterFunc<T>::execute(
149 const carto::VolumeRef<T> & volume,
151 ) const
152 {
153 StructuredConstVolume<T> volse( *volume, *se );
154 return MathUtil<T>::max( volse.begin(), volse.end() );
155 }
156
157 //--------------------------------------------------------------------------
158 // MinFilterFunc
159 //--------------------------------------------------------------------------
160 template <class T> inline
161 T MinFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
162 {
163 return carto::VolumeUtil<T>::min(volume);
164 }
165
166 template <class T> inline
167 T MinFilterFunc<T>::execute(
168 const carto::VolumeRef<T> & volume,
169 const carto::rc_ptr<StructuringElement> & se
170 ) const
171 {
172 StructuredConstVolume<T> volse( *volume, *se );
173 return MathUtil<T>::min( volse.begin(), volse.end() );
174 }
175
176 //--------------------------------------------------------------------------
177 // MedianFilterFunc
178 //--------------------------------------------------------------------------
179 template <class T> inline
180 T MedianFilterFunc<T>::execute( const carto::VolumeRef<T> & volume ) const
181 {
182 return MathUtil<T>::median( volume.begin(), volume.end() );
183 }
184
185 template <class T> inline
186 T MedianFilterFunc<T>::execute(
187 const carto::VolumeRef<T> & volume,
188 const carto::rc_ptr<StructuringElement> & se
189 ) const
190 {
191 StructuredConstVolume<T> volse( *volume, *se );
192 return MathUtil<T>::median( volse.begin(), volse.end() );
193 }
194
195 //--------------------------------------------------------------------------
196 // NotNullMedianFilterFunc
197 //--------------------------------------------------------------------------
198 template <class T> inline
199 T NotNullMedianFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
200 {
201 return MathUtil<T>::notnull_median( volume.begin(), volume.end() );
202 }
203
204 template <class T> inline
205 T NotNullMedianFilterFunc<T>::execute(
206 const carto::VolumeRef<T> & volume,
207 const carto::rc_ptr<StructuringElement> & se
208 ) const
209 {
210 StructuredConstVolume<T> volse( *volume, *se );
211 return MathUtil<T>::notnull_median( volse.begin(), volse.end() );
212 }
213
214 //--------------------------------------------------------------------------
215 // MeanFilterFunc
216 //--------------------------------------------------------------------------
217 template <class T> inline
218 T MeanFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
219 {
220 return MathUtil<T>::mean( volume.begin(), volume.end() );
221 }
222
223 template <class T> inline
224 T MeanFilterFunc<T>::execute(
225 const carto::VolumeRef<T> & volume,
226 const carto::rc_ptr<StructuringElement> & se
227 ) const
228 {
229 StructuredConstVolume<T> volse( *volume, *se );
230 return MathUtil<T>::mean( volse.begin(), volse.end() );
231 }
232
233 //--------------------------------------------------------------------------
234 // NotNullMeanFilterFunc
235 //--------------------------------------------------------------------------
236 template <class T> inline
237 T NotNullMeanFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
238 {
239 return MathUtil<T>::notnull_mean( volume.begin(), volume.end() );
240 }
241
242 template <class T> inline
243 T NotNullMeanFilterFunc<T>::execute(
244 const carto::VolumeRef<T> & volume,
245 const carto::rc_ptr<StructuringElement> & se
246 ) const
247 {
248 StructuredConstVolume<T> volse( *volume, *se );
249 return MathUtil<T>::notnull_mean( volse.begin(), volse.end() );
250 }
251
252 //--------------------------------------------------------------------------
253 // MajorityFilterFunc
254 //--------------------------------------------------------------------------
255 template <class T> inline
256 T MajorityFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
257 {
258 return MathUtil<T>::majority( volume.begin(), volume.end() );
259 }
260
261 template <class T> inline
262 T MajorityFilterFunc<T>::execute(
263 const carto::VolumeRef<T> & volume,
264 const carto::rc_ptr<StructuringElement> & se
265 ) const
266 {
267 StructuredConstVolume<T> volse( *volume, *se );
268 return MathUtil<T>::majority( volse.begin(), volse.end() );
269 }
270
271 //--------------------------------------------------------------------------
272 // NotNullMajorityFilterFunc
273 //--------------------------------------------------------------------------
274 template <class T> inline
275 T NotNullMajorityFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
276 {
277 return MathUtil<T>::notnull_majority( volume.begin(), volume.end() );
278 }
279
280 template <class T> inline
281 T NotNullMajorityFilterFunc<T>::execute(
282 const carto::VolumeRef<T> & volume,
283 const carto::rc_ptr<StructuringElement> & se
284 ) const
285 {
286 StructuredConstVolume<T> volse( *volume, *se );
287 return MathUtil<T>::notnull_majority( volse.begin(), volse.end() );
288 }
289
290 //--------------------------------------------------------------------------
291 // ExtremaDifferenceFilterFunc
292 //--------------------------------------------------------------------------
293 template <class T> inline
294 T ExtremaDifferenceFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
295 {
296 return MathUtil<T>::extrema_difference( volume.begin(), volume.end() );
297 }
298
299 template <class T> inline
300 T ExtremaDifferenceFilterFunc<T>::execute(
301 const carto::VolumeRef<T> & volume,
302 const carto::rc_ptr<StructuringElement> & se
303 ) const
304 {
305 StructuredConstVolume<T> volse( *volume, *se );
306 return MathUtil<T>::extrema_difference( volse.begin(), volse.end() );
307 }
308
309 //--------------------------------------------------------------------------
310 // SumFilterFunc
311 //--------------------------------------------------------------------------
312 template <class T> inline
313 T SumFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
314 {
315 return MathUtil<T>::sum( volume.begin(), volume.end() );
316 }
317
318 template <class T> inline
319 T SumFilterFunc<T>::execute(
320 const carto::VolumeRef<T> & volume,
321 const carto::rc_ptr<StructuringElement> & se
322 ) const
323 {
324 StructuredConstVolume<T> volse( *volume, *se );
325 return MathUtil<T>::sum( volse.begin(), volse.end() );
326 }
327
328 //--------------------------------------------------------------------------
329 // VarFilterFunc
330 //--------------------------------------------------------------------------
331 template <class T> inline
332 T VarFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
333 {
334 return MathUtil<T>::variance( volume.begin(), volume.end() );
335 }
336
337 template <class T> inline
338 T VarFilterFunc<T>::execute(
339 const carto::VolumeRef<T> & volume,
340 const carto::rc_ptr<StructuringElement> & se
341 ) const
342 {
343 StructuredConstVolume<T> volse( *volume, *se );
344 return MathUtil<T>::variance( volse.begin(), volse.end() );
345 }
346
347 //--------------------------------------------------------------------------
348 // StDevFilterFunc
349 //--------------------------------------------------------------------------
350 template <class T> inline
351 T StDevFilterFunc<T>::execute( const carto::VolumeRef<T>& volume ) const
352 {
353 return MathUtil<T>::stdev( volume.begin(), volume.end() );
354 }
355
356 template <class T> inline
357 T StDevFilterFunc<T>::execute(
358 const carto::VolumeRef<T> & volume,
359 const carto::rc_ptr<StructuringElement> & se
360 ) const
361 {
362 StructuredConstVolume<T> volse( *volume, *se );
363 return MathUtil<T>::stdev( volse.begin(), volse.end() );
364 }
365
366} // namespace aims
367
368#endif
static std::set< std::string > names()
List all function ids registered in the factory.
static std::map< std::string, carto::rc_ptr< ElementFilteringFunction< T > > > & _map()
static ElementFilteringFunction< T > * create(const std::string &name, carto::Object options=carto::none())
Build and return the ElementFilteringFunction associated with the id name.
static void registerFunction(const std::string &name, const ElementFilteringFunction< T > &func)
Register a ElementFilterigFunction into the factory.
Base class for filtering functions applied in a structuring element.
virtual ElementFilteringFunction< T > * clone() const =0
clone
virtual void setOptions(const carto::Object &)
Set the parameters of the filters If a parameter value is not set in the options object,...
static T notnull_mean(Iterator b, Iterator e)
static T median(Iterator b, Iterator e, T default_value=(T) 0)
static T mean(Iterator b, Iterator e)
static T variance(Iterator b, Iterator e)
static T extrema_difference(Iterator b, Iterator e)
static T min(Iterator b, Iterator e, T default_value=std::numeric_limits< T >::max())
static T majority(Iterator b, Iterator e, T default_value=(T) 0)
static T notnull_median(Iterator b, Iterator e, T default_value=(T) 0)
static T stdev(Iterator b, Iterator e)
static T max(Iterator b, Iterator e, T default_value=carto::min_limit< T >())
static T sum(Iterator b, Iterator e)
static T notnull_majority(Iterator b, Iterator e, T default_value=(T) 0)
iterator end()
iterator begin()