CBICA Toolkit  1.0.0
itkNaryMeanImageFilter.h
Go to the documentation of this file.
1 /**
2 \file itkNaryMeanImageFilter.h
3 
4 \brief Declaration & Implementation of the NaryMeanImageFilter class
5 
6 https://www.cbica.upenn.edu/sbia/software/ <br>
7 software@cbica.upenn.edu
8 
9 Copyright (c) 2015 University of Pennsylvania. All rights reserved. <br>
10 See COPYING file or https://www.cbica.upenn.edu/sbia/software/license.html
11 
12 */
13 #pragma once
14 
15 #include "itkNaryFunctorImageFilter.h"
16 #include "itkNumericTraits.h"
17 
18 namespace itk
19 {
20 
21  namespace Functor
22  {
23  /**
24  \class Mean
25 
26  \brief Helper class for calculating mean of images which interfaces with NaryMeanImageFilter
27  */
28  template< class TInput, class TOutput >
29  class Mean
30  {
31  public:
32  typedef typename NumericTraits< TOutput >::RealType RealType;
33  Mean() {}
34  ~Mean() {}
35  inline TOutput operator()( const std::vector< TInput > & B)
36  {
37  RealType meanVal = NumericTraits< TOutput >::Zero;
38  for( unsigned int i=0; i< B.size(); i++ )
39  {
40  meanVal += static_cast< RealType >(B[i]);
41  }
42  meanVal = meanVal / B.size();
43 
44  return static_cast<TOutput>( meanVal );
45  }
46  bool operator== (const Mean&) const
47  {
48  return true;
49  }
50  bool operator!= (const Mean&) const
51  {
52  return false;
53  }
54  };
55  }
56 
57  /**
58  \class NaryMeanImageFilter
59 
60  \brief Implements an operator for pixel-wise averaging of two images.
61 
62  This class is parametrized over the types of the two
63  input images and the type of the output image.
64  Numeric conversions (castings) are done by the C++ defaults.
65 
66  The pixel type of the input 1 image must have a valid defintion of
67  the operator+ with a pixel type of the image 2. This condition is
68  required because internally this filter will perform the operation
69 
70  <code>pixel_from_image_1 + pixel_from_image_2</code>
71 
72  Additionally the type resulting from the sum, will be cast to
73  the pixel type of the output image.
74 
75  \warning No numeric overflow checking is performed in this filter.
76 
77  \ingroup IntensityImageFilters Multithreaded
78  */
79 
80  template <class TInputImage, class TOutputImage>
81  class ITK_EXPORT NaryMeanImageFilter :
82  public
83  NaryFunctorImageFilter<TInputImage,TOutputImage,
84  Functor::Mean<typename TInputImage::PixelType, typename TOutputImage::PixelType > >
85  {
86  public:
87  //! Standard class typedefs.
89  typedef NaryFunctorImageFilter<TInputImage,TOutputImage,
90  Functor::Mean<typename TInputImage::PixelType,
91  typename TInputImage::PixelType > > Superclass;
92  typedef SmartPointer<Self> Pointer;
93  typedef SmartPointer<const Self> ConstPointer;
94 
95  //! Method for creation through the object factory.
96  itkNewMacro(Self);
97 
98  //! Runtime information support.
99  itkTypeMacro(NaryMeanImageFilter,
100  NaryFunctorImageFilter);
101 
102  #ifdef ITK_USE_CONCEPT_CHECKING
103  //! Begin concept checking
104  itkConceptMacro(InputConvertibleToOutputCheck,
105  (Concept::Convertible<typename TInputImage::PixelType,
106  typename TOutputImage::PixelType>));
107  itkConceptMacro(InputHasZeroCheck,
108  (Concept::HasZero<typename TInputImage::PixelType>));
109  //! End concept checking
110  #endif
111 
112  protected:
114  virtual ~NaryMeanImageFilter() {}
115 
116  private:
117  NaryMeanImageFilter(const Self&); // purposely not implemented
118  void operator=(const Self&); // purposely not implemented
119 
120  };
121 
122 } // end namespace itk
123 
Helper class for calculating mean of images which interfaces with NaryMeanImageFilter.
Definition: itkNaryMeanImageFilter.h:29
NaryMeanImageFilter Self
Standard class typedefs.
Definition: itkNaryMeanImageFilter.h:88
Implements an operator for pixel-wise averaging of two images.
Definition: itkNaryMeanImageFilter.h:81