ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBinaryStatisticsKeepNObjectsImageFilter.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 __itkBinaryStatisticsKeepNObjectsImageFilter_h
00019 #define __itkBinaryStatisticsKeepNObjectsImageFilter_h
00020 
00021 #include "itkBinaryImageToLabelMapFilter.h"
00022 #include "itkStatisticsLabelMapFilter.h"
00023 #include "itkStatisticsKeepNObjectsLabelMapFilter.h"
00024 #include "itkLabelMapToBinaryImageFilter.h"
00025 
00026 namespace itk
00027 {
00045 template< class TInputImage, class TFeatureImage >
00046 class ITK_EXPORT BinaryStatisticsKeepNObjectsImageFilter:
00047   public ImageToImageFilter< TInputImage, TInputImage >
00048 {
00049 public:
00051   typedef BinaryStatisticsKeepNObjectsImageFilter        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 SizeValueType LabelType;
00083 
00084   typedef StatisticsLabelObject< LabelType, itkGetStaticConstMacro(ImageDimension) >     LabelObjectType;
00085   typedef LabelMap< LabelObjectType >                                                    LabelMapType;
00086   typedef BinaryImageToLabelMapFilter< InputImageType, LabelMapType >                    LabelizerType;
00087   typedef StatisticsLabelMapFilter< LabelMapType, TFeatureImage >                        LabelObjectValuatorType;
00088   typedef typename LabelObjectType::AttributeType                                        AttributeType;
00089   typedef StatisticsKeepNObjectsLabelMapFilter< LabelMapType >                           KeepNObjectsType;
00090   typedef LabelMapToBinaryImageFilter< LabelMapType, OutputImageType >                   BinarizerType;
00091 
00093   itkNewMacro(Self);
00094 
00096   itkTypeMacro(BinaryStatisticsKeepNObjectsImageFilter,
00097                ImageToImageFilter);
00098 
00105   itkSetMacro(FullyConnected, bool);
00106   itkGetConstReferenceMacro(FullyConnected, bool);
00107   itkBooleanMacro(FullyConnected);
00109 
00110 #ifdef ITK_USE_CONCEPT_CHECKING
00111 
00112   itkConceptMacro( InputEqualityComparableCheck,
00113                    ( Concept::EqualityComparable< InputImagePixelType > ) );
00114   itkConceptMacro( IntConvertibleToInputCheck,
00115                    ( Concept::Convertible< int, InputImagePixelType > ) );
00116   itkConceptMacro( InputOStreamWritableCheck,
00117                    ( Concept::OStreamWritable< InputImagePixelType > ) );
00118 
00120 #endif
00121 
00126   itkSetMacro(BackgroundValue, OutputImagePixelType);
00127   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00129 
00134   itkSetMacro(ForegroundValue, OutputImagePixelType);
00135   itkGetConstMacro(ForegroundValue, OutputImagePixelType);
00137 
00141   itkGetConstMacro(NumberOfObjects, SizeValueType);
00142   itkSetMacro(NumberOfObjects, SizeValueType);
00144 
00150   itkGetConstMacro(ReverseOrdering, bool);
00151   itkSetMacro(ReverseOrdering, bool);
00152   itkBooleanMacro(ReverseOrdering);
00154 
00159   itkGetConstMacro(Attribute, AttributeType);
00160   itkSetMacro(Attribute, AttributeType);
00161   void SetAttribute(const std::string & s)
00162   {
00163     this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
00164   }
00166 
00168   void SetFeatureImage(const TFeatureImage *input)
00169   {
00170     // Process object is not const-correct so the const casting is required.
00171     this->SetNthInput( 1, const_cast< TFeatureImage * >( input ) );
00172   }
00173 
00175   const FeatureImageType * GetFeatureImage()
00176   {
00177     return static_cast< const FeatureImageType * >( this->ProcessObject::GetInput(1) );
00178   }
00179 
00181   void SetInput1(const InputImageType *input)
00182   {
00183     this->SetInput(input);
00184   }
00185 
00187   void SetInput2(const FeatureImageType *input)
00188   {
00189     this->SetFeatureImage(input);
00190   }
00191 
00192 protected:
00193   BinaryStatisticsKeepNObjectsImageFilter();
00194   ~BinaryStatisticsKeepNObjectsImageFilter() {}
00195   void PrintSelf(std::ostream & os, Indent indent) const;
00196 
00200   void GenerateInputRequestedRegion();
00201 
00203   void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) );
00204 
00207   void GenerateData();
00208 
00209 private:
00210   BinaryStatisticsKeepNObjectsImageFilter(const Self &); //purposely not
00211                                                          // implemented
00212   void operator=(const Self &);                          //purposely not
00213                                                          // implemented
00214 
00215   bool                 m_FullyConnected;
00216   OutputImagePixelType m_BackgroundValue;
00217   OutputImagePixelType m_ForegroundValue;
00218   SizeValueType        m_NumberOfObjects;
00219   bool                 m_ReverseOrdering;
00220   AttributeType        m_Attribute;
00221 }; // end of class
00222 } // end namespace itk
00223 
00224 #ifndef ITK_MANUAL_INSTANTIATION
00225 #include "itkBinaryStatisticsKeepNObjectsImageFilter.hxx"
00226 #endif
00227 
00228 #endif
00229