ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkHistogramThresholdImageFilter.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 
00019 #ifndef __itkHistogramThresholdImageFilter_h
00020 #define __itkHistogramThresholdImageFilter_h
00021 
00022 #include "itkImageToImageFilter.h"
00023 #include "itkHistogram.h"
00024 #include "itkHistogramThresholdCalculator.h"
00025 
00026 namespace itk {
00027 
00059 template<class TInputImage, class TOutputImage, class TMaskImage=TOutputImage>
00060 class ITK_EXPORT HistogramThresholdImageFilter :
00061     public ImageToImageFilter<TInputImage, TOutputImage>
00062 {
00063 public:
00065   typedef HistogramThresholdImageFilter                    Self;
00066   typedef ImageToImageFilter<TInputImage,TOutputImage>     Superclass;
00067   typedef SmartPointer<Self>                               Pointer;
00068   typedef SmartPointer<const Self>                         ConstPointer;
00069 
00071   itkNewMacro(Self);
00072 
00074   itkTypeMacro(HistogramThresholdImageFilter, ImageToImageFilter);
00075 
00076   typedef TInputImage                       InputImageType;
00077   typedef TOutputImage                      OutputImageType;
00078   typedef TMaskImage                        MaskImageType;
00079 
00081   typedef typename InputImageType::PixelType   InputPixelType;
00082   typedef typename OutputImageType::PixelType  OutputPixelType;
00083   typedef typename MaskImageType::PixelType    MaskPixelType;
00084 
00086   typedef typename InputImageType::Pointer  InputImagePointer;
00087   typedef typename OutputImageType::Pointer OutputImagePointer;
00088   typedef typename MaskImageType::Pointer   MaskImagePointer;
00089 
00090   typedef typename InputImageType::SizeType    InputSizeType;
00091   typedef typename InputImageType::IndexType   InputIndexType;
00092   typedef typename InputImageType::RegionType  InputImageRegionType;
00093   typedef typename OutputImageType::SizeType   OutputSizeType;
00094   typedef typename OutputImageType::IndexType  OutputIndexType;
00095   typedef typename OutputImageType::RegionType OutputImageRegionType;
00096   typedef typename MaskImageType::SizeType     MaskSizeType;
00097   typedef typename MaskImageType::IndexType    MaskIndexType;
00098   typedef typename MaskImageType::RegionType   MaskImageRegionType;
00099 
00100    typedef typename NumericTraits< InputPixelType >::ValueType ValueType;
00101    typedef typename NumericTraits< ValueType >::RealType       ValueRealType;
00102    typedef Statistics::Histogram< ValueRealType >              HistogramType;
00103    typedef typename HistogramType::Pointer                     HistogramPointer;
00104    typedef typename HistogramType::ConstPointer                HistogramConstPointer;
00105    typedef typename HistogramType::SizeType                    HistogramSizeType;
00106    typedef typename HistogramType::MeasurementType             HistogramMeasurementType;
00107    typedef typename HistogramType::MeasurementVectorType       HistogramMeasurementVectorType;
00108    typedef HistogramThresholdCalculator<HistogramType, InputPixelType>
00109                                                                CalculatorType;
00110    typedef typename CalculatorType::Pointer                    CalculatorPointer;
00111 
00113   itkStaticConstMacro(InputImageDimension, unsigned int,
00114                       InputImageType::ImageDimension );
00115   itkStaticConstMacro(OutputImageDimension, unsigned int,
00116                       OutputImageType::ImageDimension );
00117   itkStaticConstMacro(MaskImageDimension, unsigned int,
00118                       MaskImageType::ImageDimension );
00120 
00124   void SetMaskImage(const TMaskImage *input)
00125   {
00126     // Process object is not const-correct so the const casting is required.
00127     this->SetNthInput( 1, const_cast< TMaskImage * >( input ) );
00128   }
00129 
00131   const MaskImageType * GetMaskImage() const
00132   {
00133     return static_cast< MaskImageType * >(
00134              const_cast< DataObject * >( this->ProcessObject::GetInput(1) ) );
00135   }
00136 
00138   void SetInput1(const TInputImage *input)
00139   {
00140     this->SetInput(input);
00141   }
00142 
00144   void SetInput2(const TMaskImage *input)
00145   {
00146     this->SetMaskImage(input);
00147   }
00148 
00151   itkSetMacro(OutsideValue,OutputPixelType);
00152 
00154   itkGetConstMacro(OutsideValue,OutputPixelType);
00155 
00158   itkSetMacro(InsideValue,OutputPixelType);
00159 
00161   itkGetConstMacro(InsideValue,OutputPixelType);
00162 
00164   itkSetMacro(NumberOfHistogramBins, unsigned int);
00165   itkGetConstMacro(NumberOfHistogramBins, unsigned int);
00167 
00170   itkSetMacro(AutoMinimumMaximum, bool);
00171   itkGetConstMacro(AutoMinimumMaximum, bool);
00172   itkBooleanMacro(AutoMinimumMaximum);
00174 
00178   itkSetMacro(MaskOutput, bool);
00179   itkGetConstMacro(MaskOutput, bool);
00180   itkBooleanMacro(MaskOutput);
00182 
00186   itkSetMacro(MaskValue, MaskPixelType);
00187   itkGetConstMacro(MaskValue, MaskPixelType);
00189 
00191   itkGetConstMacro(Threshold,InputPixelType);
00192 
00194   itkSetObjectMacro(Calculator, CalculatorType);
00195   itkGetObjectMacro(Calculator, CalculatorType);
00197 
00198 #ifdef ITK_USE_CONCEPT_CHECKING
00199 
00200   itkConceptMacro(OutputEqualityComparableCheck,
00201     (Concept::EqualityComparable<OutputPixelType>));
00202   itkConceptMacro(InputOStreamWritableCheck,
00203     (Concept::OStreamWritable<InputPixelType>));
00204   itkConceptMacro(OutputOStreamWritableCheck,
00205     (Concept::OStreamWritable<OutputPixelType>));
00206 
00208 #endif
00209 protected:
00210   HistogramThresholdImageFilter();
00211   ~HistogramThresholdImageFilter(){};
00212   void PrintSelf(std::ostream& os, Indent indent) const;
00214 
00215   void GenerateInputRequestedRegion();
00216   void GenerateData ();
00217 
00218   OutputPixelType     m_InsideValue;
00219   OutputPixelType     m_OutsideValue;
00220   InputPixelType      m_Threshold;
00221   MaskPixelType       m_MaskValue;
00222   CalculatorPointer   m_Calculator;
00223   unsigned            m_NumberOfHistogramBins;
00224   bool                m_AutoMinimumMaximum;
00225   bool                m_MaskOutput;
00226 
00227 private:
00228   HistogramThresholdImageFilter(const Self&); //purposely not implemented
00229   void operator=(const Self&); //purposely not implemented
00230 
00231 }; // end of class
00232 
00233 } // end namespace itk
00234 
00235 #ifndef ITK_MANUAL_INSTANTIATION
00236 #include "itkHistogramThresholdImageFilter.hxx"
00237 #endif
00238 
00239 #endif
00240