Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkLabelStatisticsImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLabelStatisticsImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/05/21 19:14:07 $
00007   Version:   $Revision: 1.2 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkLabelStatisticsImageFilter_h
00018 #define __itkLabelStatisticsImageFilter_h
00019 
00020 #include "itkImageToImageFilter.h"
00021 #include "itkNumericTraits.h"
00022 #include "itkArray.h"
00023 #include "itkSimpleDataObjectDecorator.h"
00024 #include "itk_hash_map.h"
00025 #include <vector>
00026 
00027 namespace itk {
00028 
00046 template<class TInputImage, class TLabelImage>
00047 class ITK_EXPORT LabelStatisticsImageFilter : 
00048     public ImageToImageFilter<TInputImage, TInputImage>
00049 {
00050 public:
00052   typedef LabelStatisticsImageFilter Self;
00053   typedef ImageToImageFilter<TInputImage,TInputImage>  Superclass;
00054   typedef SmartPointer<Self>        Pointer;
00055   typedef SmartPointer<const Self>  ConstPointer;
00056   
00058   itkNewMacro(Self);  
00059 
00061   itkTypeMacro(LabelStatisticsImageFilter, ImageToImageFilter);
00062   
00064   typedef typename TInputImage::Pointer InputImagePointer;
00065   typedef typename TInputImage::RegionType RegionType ;
00066   typedef typename TInputImage::SizeType SizeType ;
00067   typedef typename TInputImage::IndexType IndexType ;
00068   typedef typename TInputImage::PixelType PixelType ;
00069 
00071   typedef TLabelImage LabelImageType;
00072   typedef typename TLabelImage::Pointer LabelImagePointer;
00073   typedef typename TLabelImage::RegionType LabelRegionType ;
00074   typedef typename TLabelImage::SizeType LabelSizeType ;
00075   typedef typename TLabelImage::IndexType LabelIndexType ;
00076   typedef typename TLabelImage::PixelType LabelPixelType ;
00077   
00079   itkStaticConstMacro(ImageDimension, unsigned int,
00080                       TInputImage::ImageDimension ) ;
00081 
00083   typedef typename NumericTraits<PixelType>::RealType RealType;
00084 
00086   typedef typename DataObject::Pointer DataObjectPointer;
00087 
00089   typedef SimpleDataObjectDecorator<RealType> RealObjectType;
00090 
00092   class LabelStatistics
00093   {
00094   public:
00095     LabelStatistics()
00096       {
00097         // initialized to the default values
00098         m_Count = 0;
00099         m_Sum = NumericTraits<RealType>::Zero;
00100         m_SumOfSquares = NumericTraits<RealType>::Zero;
00101 
00102         // Set such that the first pixel encountered can be compared
00103         m_Minimum = NumericTraits<RealType>::max();
00104         m_Maximum = NumericTraits<RealType>::NonpositiveMin();
00105 
00106         // Default these to zero
00107         m_Mean = NumericTraits<RealType>::Zero;
00108         m_Sigma = NumericTraits<RealType>::Zero;
00109         m_Variance = NumericTraits<RealType>::Zero;
00110       }
00111     
00112     unsigned long m_Count;
00113     RealType m_Minimum;
00114     RealType m_Maximum;
00115     RealType m_Mean;
00116     RealType m_Sum;
00117     RealType m_SumOfSquares;
00118     RealType m_Sigma;
00119     RealType m_Variance;
00120   };
00121   
00123   typedef itk::hash_map<LabelPixelType, LabelStatistics> MapType;
00124   typedef typename itk::hash_map<LabelPixelType, LabelStatistics>::iterator MapIterator;
00125   typedef typename itk::hash_map<LabelPixelType, LabelStatistics>::const_iterator MapConstIterator;
00126 
00128   void SetLabelInput(TLabelImage *input)
00129     {
00130       // Process object is not const-correct so the const casting is required.
00131       this->SetNthInput(1, const_cast<TLabelImage *>(input) );
00132     }
00133 
00135   LabelImageType * GetLabelInput()
00136     {
00137       return static_cast<LabelImageType*>(const_cast<DataObject *>(this->ProcessObject::GetInput(1)));
00138     }
00139 
00142   bool HasLabel(LabelPixelType label) const
00143     {
00144       return m_LabelStatistics.find(label) != m_LabelStatistics.end();
00145     }
00146 
00148   unsigned long GetNumberOfObjects() const
00149     {
00150       return m_LabelStatistics.size();
00151     }
00152   unsigned long GetNumberOfLabels() const
00153     {
00154       return this->GetNumberOfObjects();
00155     }
00156 
00157   
00159   RealType GetMinimum(LabelPixelType label) const;
00160 
00162   RealType GetMaximum(LabelPixelType label) const;
00163 
00165   RealType GetMean(LabelPixelType label) const;
00166 
00168   RealType GetSigma(LabelPixelType label) const;
00169 
00171   RealType GetVariance(LabelPixelType label) const;
00172 
00174   RealType GetSum(LabelPixelType label) const;
00175 
00177   unsigned long GetCount(LabelPixelType label) const;
00178 
00179 protected:
00180   LabelStatisticsImageFilter();
00181   ~LabelStatisticsImageFilter(){};
00182   void PrintSelf(std::ostream& os, Indent indent) const;
00183 
00185   void AllocateOutputs();      
00186 
00188   void BeforeThreadedGenerateData ();
00189   
00191   void AfterThreadedGenerateData ();
00192   
00194   void  ThreadedGenerateData (const RegionType& 
00195                               outputRegionForThread,
00196                               int threadId) ;
00197 
00198   // Override since the filter needs all the data for the algorithm
00199   void GenerateInputRequestedRegion();
00200 
00201   // Override since the filter produces all of its output
00202   void EnlargeOutputRequestedRegion(DataObject *data);
00203 
00204 private:
00205   LabelStatisticsImageFilter(const Self&); //purposely not implemented
00206   void operator=(const Self&); //purposely not implemented
00207 
00208   std::vector<MapType>  m_LabelStatisticsPerThread;
00209   MapType               m_LabelStatistics;
00210 
00211 } ; // end of class
00212 
00213 } // end namespace itk
00214   
00215 #ifndef ITK_MANUAL_INSTANTIATION
00216 #include "itkLabelStatisticsImageFilter.txx"
00217 #endif
00218 
00219 #endif

Generated at Wed Mar 30 00:01:12 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000