ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLabelStatisticsKeepNObjectsImageFilter.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 __itkLabelStatisticsKeepNObjectsImageFilter_h
00019 #define __itkLabelStatisticsKeepNObjectsImageFilter_h
00020 
00021 #include "itkLabelImageToLabelMapFilter.h"
00022 #include "itkStatisticsLabelMapFilter.h"
00023 #include "itkStatisticsKeepNObjectsLabelMapFilter.h"
00024 #include "itkLabelMapToLabelImageFilter.h"
00025 
00026 namespace itk
00027 {
00045 template< class TInputImage, class TFeatureImage >
00046 class ITK_EXPORT LabelStatisticsKeepNObjectsImageFilter:
00047   public ImageToImageFilter< TInputImage, TInputImage >
00048 {
00049 public:
00051   typedef LabelStatisticsKeepNObjectsImageFilter         Self;
00052   typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
00053   typedef SmartPointer< Self >                           Pointer;
00054   typedef SmartPointer< const Self >                     ConstPointer;
00055 
00057   typedef TInputImage                            InputImageType;
00058   typedef TInputImage                            OutputImageType;
00059   typedef typename InputImageType::Pointer       InputImagePointer;
00060   typedef typename InputImageType::ConstPointer  InputImageConstPointer;
00061   typedef typename InputImageType::RegionType    InputImageRegionType;
00062   typedef typename InputImageType::PixelType     InputImagePixelType;
00063   typedef typename OutputImageType::Pointer      OutputImagePointer;
00064   typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
00065   typedef typename OutputImageType::RegionType   OutputImageRegionType;
00066   typedef typename OutputImageType::PixelType    OutputImagePixelType;
00067 
00068   typedef TFeatureImage                           FeatureImageType;
00069   typedef typename FeatureImageType::Pointer      FeatureImagePointer;
00070   typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer;
00071   typedef typename FeatureImageType::PixelType    FeatureImagePixelType;
00072 
00074   itkStaticConstMacro(InputImageDimension, unsigned int,
00075                       TInputImage::ImageDimension);
00076   itkStaticConstMacro(OutputImageDimension, unsigned int,
00077                       TInputImage::ImageDimension);
00078   itkStaticConstMacro(ImageDimension, unsigned int,
00079                       TInputImage::ImageDimension);
00081 
00082   typedef StatisticsLabelObject< InputImagePixelType, itkGetStaticConstMacro(ImageDimension) > LabelObjectType;
00083   typedef LabelMap< LabelObjectType >                                                          LabelMapType;
00084   typedef LabelImageToLabelMapFilter< InputImageType, LabelMapType >                           LabelizerType;
00085   typedef StatisticsLabelMapFilter< LabelMapType, TFeatureImage >                              LabelObjectValuatorType;
00086   typedef typename LabelObjectType::AttributeType                                              AttributeType;
00087   typedef StatisticsKeepNObjectsLabelMapFilter< LabelMapType >                                 KeepNObjectsType;
00088   typedef LabelMapToLabelImageFilter< LabelMapType, OutputImageType >                          BinarizerType;
00089 
00091   itkNewMacro(Self);
00092 
00094   itkTypeMacro(LabelStatisticsKeepNObjectsImageFilter,
00095                ImageToImageFilter);
00096 
00097 #ifdef ITK_USE_CONCEPT_CHECKING
00098 
00099   itkConceptMacro( InputEqualityComparableCheck,
00100                    ( Concept::EqualityComparable< InputImagePixelType > ) );
00101   itkConceptMacro( IntConvertibleToInputCheck,
00102                    ( Concept::Convertible< int, InputImagePixelType > ) );
00103   itkConceptMacro( InputOStreamWritableCheck,
00104                    ( Concept::OStreamWritable< InputImagePixelType > ) );
00105 
00107 #endif
00108 
00113   itkSetMacro(BackgroundValue, OutputImagePixelType);
00114   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00116 
00120   itkGetConstMacro(NumberOfObjects, SizeValueType);
00121   itkSetMacro(NumberOfObjects, SizeValueType);
00123 
00129   itkGetConstMacro(ReverseOrdering, bool);
00130   itkSetMacro(ReverseOrdering, bool);
00131   itkBooleanMacro(ReverseOrdering);
00133 
00138   itkGetConstMacro(Attribute, AttributeType);
00139   itkSetMacro(Attribute, AttributeType);
00140   void SetAttribute(const std::string & s)
00141   {
00142     this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
00143   }
00145 
00147   void SetFeatureImage(const TFeatureImage *input)
00148   {
00149     // Process object is not const-correct so the const casting is required.
00150     this->SetNthInput( 1, const_cast< TFeatureImage * >( input ) );
00151   }
00152 
00154   const FeatureImageType * GetFeatureImage()
00155   {
00156     return static_cast< const FeatureImageType * >( this->ProcessObject::GetInput(1) );
00157   }
00158 
00160   void SetInput1(const InputImageType *input)
00161   {
00162     this->SetInput(input);
00163   }
00164 
00166   void SetInput2(const FeatureImageType *input)
00167   {
00168     this->SetFeatureImage(input);
00169   }
00170 
00171 protected:
00172   LabelStatisticsKeepNObjectsImageFilter();
00173   ~LabelStatisticsKeepNObjectsImageFilter() {}
00174   void PrintSelf(std::ostream & os, Indent indent) const;
00175 
00179   void GenerateInputRequestedRegion();
00180 
00182   void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) );
00183 
00186   void GenerateData();
00187 
00188 private:
00189   LabelStatisticsKeepNObjectsImageFilter(const Self &); //purposely not
00190                                                         // implemented
00191   void operator=(const Self &);                         //purposely not
00192                                                         // implemented
00193 
00194   OutputImagePixelType m_BackgroundValue;
00195   SizeValueType        m_NumberOfObjects;
00196   bool                 m_ReverseOrdering;
00197   AttributeType        m_Attribute;
00198 }; // end of class
00199 } // end namespace itk
00200 
00201 #ifndef ITK_MANUAL_INSTANTIATION
00202 #include "itkLabelStatisticsKeepNObjectsImageFilter.hxx"
00203 #endif
00204 
00205 #endif
00206