ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMedianProjectionImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMedianProjectionImageFilter_h
00019 #define __itkMedianProjectionImageFilter_h
00020 
00021 #include "itkProjectionImageFilter.h"
00022 #include "itkConceptChecking.h"
00023 
00024 #include <vector>
00025 #include <algorithm>
00026 
00027 namespace itk
00028 {
00050 namespace Functor
00051 {
00052 template< class TInputPixel >
00053 class MedianAccumulator
00054 {
00055 public:
00056   MedianAccumulator( SizeValueType size)
00057   {
00058     m_Values.reserve(size);
00059   }
00060 
00061   ~MedianAccumulator(){}
00062 
00063   inline void Initialize()
00064   {
00065     m_Values.clear();
00066   }
00067 
00068   inline void operator()(const TInputPixel & input)
00069   {
00070     m_Values.push_back(input);
00071   }
00072 
00073   inline TInputPixel GetValue()
00074   {
00075     typedef typename std::vector< TInputPixel >::iterator ContainerIterator;
00076     ContainerIterator medianIterator = m_Values.begin() +  m_Values.size() / 2;
00077     std::nth_element( m_Values.begin(), medianIterator, m_Values.end() );
00078     return *medianIterator;
00079   }
00080 
00081   std::vector< TInputPixel > m_Values;
00082 };
00083 } // end namespace Function
00084 
00085 template< class TInputImage, class TOutputImage >
00086 class ITK_EXPORT MedianProjectionImageFilter:public
00087   ProjectionImageFilter< TInputImage, TOutputImage,
00088                          Functor::MedianAccumulator< typename TInputImage::PixelType > >
00089 {
00090 public:
00091   typedef MedianProjectionImageFilter Self;
00092   typedef ProjectionImageFilter< TInputImage, TOutputImage,
00093                                  Functor::MedianAccumulator<
00094                                    typename TInputImage::PixelType > > Superclass;
00095 
00096   typedef SmartPointer< Self >       Pointer;
00097   typedef SmartPointer< const Self > ConstPointer;
00098 
00100   itkTypeMacro(MedianProjectionImageFilter, ProjectionImageFilter);
00101 
00103   itkNewMacro(Self);
00104 
00105 #ifdef ITK_USE_CONCEPT_CHECKING
00106 
00109 #endif
00110 protected:
00111   MedianProjectionImageFilter() {}
00112   virtual ~MedianProjectionImageFilter() {}
00113 private:
00114   MedianProjectionImageFilter(const Self &); //purposely not implemented
00115   void operator=(const Self &);              //purposely not implemented
00116 };                                           // end MedianProjectionImageFilter
00117 } //end namespace itk
00119 
00120 #endif
00121