ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkScalarImageKmeansImageFilter.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 __itkScalarImageKmeansImageFilter_h
00019 #define __itkScalarImageKmeansImageFilter_h
00020 
00021 
00022 #include "itkKdTree.h"
00023 #include "itkKdTreeBasedKmeansEstimator.h"
00024 #include "itkWeightedCentroidKdTreeGenerator.h"
00025 
00026 #include "itkSampleClassifierFilter.h"
00027 #include "itkImageToListSampleAdaptor.h"
00028 #include "itkMinimumDecisionRule.h"
00029 
00030 #include "itkRegionOfInterestImageFilter.h"
00031 
00032 #include <vector>
00033 
00034 namespace itk
00035 {
00062 template< class TInputImage,
00063           class TOutputImage = Image< unsigned char, ::itk::GetImageDimension< TInputImage >::ImageDimension > >
00064 class ITK_EXPORT ScalarImageKmeansImageFilter:
00065   public ImageToImageFilter< TInputImage, TOutputImage >
00066 {
00067 public:
00069   itkStaticConstMacro(ImageDimension, unsigned int,
00070                       TInputImage::ImageDimension);
00071 
00073   typedef TInputImage  InputImageType;
00074   typedef TOutputImage OutputImageType;
00075 
00077   typedef ScalarImageKmeansImageFilter                          Self;
00078   typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass;
00079   typedef SmartPointer< Self >                                  Pointer;
00080   typedef SmartPointer< const Self >                            ConstPointer;
00081 
00083   itkNewMacro(Self);
00084 
00086   itkTypeMacro(ScalarImageKmeansImageFilter, ImageToImageFilter);
00087 
00089   typedef typename InputImageType::PixelType  InputPixelType;
00090   typedef typename OutputImageType::PixelType OutputPixelType;
00091 
00093   typedef typename NumericTraits< InputPixelType >::RealType RealPixelType;
00094 
00096   typedef itk::Statistics::ImageToListSampleAdaptor< InputImageType > AdaptorType;
00097 
00099   typedef typename AdaptorType::MeasurementVectorType MeasurementVectorType;
00100 
00101   typedef itk::Statistics::DistanceToCentroidMembershipFunction< MeasurementVectorType > MembershipFunctionType;
00102   typedef itk::Statistics::SampleClassifierFilter< AdaptorType >                         ClassifierType;
00103   typedef itk::Statistics::MinimumDecisionRule  DecisionRuleType;
00104 
00105   typedef typename ClassifierType::ClassLabelVectorType ClassLabelVectorType;
00106 
00107   typedef typename ClassifierType::MembershipFunctionVectorType MembershipFunctionVectorType;
00108   typedef typename MembershipFunctionType::CentroidType         MembershipFunctionOriginType;
00109 
00110   typedef typename MembershipFunctionType::Pointer MembershipFunctionPointer;
00111 
00113   typedef itk::Statistics::WeightedCentroidKdTreeGenerator< AdaptorType > TreeGeneratorType;
00114   typedef typename TreeGeneratorType::KdTreeType                          TreeType;
00115   typedef itk::Statistics::KdTreeBasedKmeansEstimator< TreeType >         EstimatorType;
00116 
00117   typedef typename EstimatorType::ParametersType ParametersType;
00118 
00119   typedef typename InputImageType::RegionType ImageRegionType;
00120 
00121   typedef RegionOfInterestImageFilter<
00122     InputImageType,
00123     InputImageType  > RegionOfInterestFilterType;
00124 
00126   void AddClassWithInitialMean(RealPixelType mean);
00127 
00129   itkGetConstReferenceMacro(FinalMeans, ParametersType);
00130 
00136   itkSetMacro(UseNonContiguousLabels, bool);
00137   itkGetConstReferenceMacro(UseNonContiguousLabels, bool);
00138   itkBooleanMacro(UseNonContiguousLabels);
00140 
00142   void SetImageRegion(const ImageRegionType & region);
00143 
00145   itkGetConstReferenceMacro(ImageRegion, ImageRegionType);
00146 
00147 #ifdef ITK_USE_CONCEPT_CHECKING
00148 
00149   itkConceptMacro( InputHasNumericTraitsCheck,
00150                    ( Concept::HasNumericTraits< InputPixelType > ) );
00151 
00153 #endif
00154 protected:
00155   ScalarImageKmeansImageFilter();
00156   virtual ~ScalarImageKmeansImageFilter() {}
00157   void PrintSelf(std::ostream & os, Indent indent) const;
00159 
00165   void GenerateData();
00166 
00167 private:
00168   ScalarImageKmeansImageFilter(const Self &); //purposely not implemented
00169   void operator=(const Self &);               //purposely not implemented
00170 
00171   typedef std::vector< RealPixelType > MeansContainer;
00172 
00173   MeansContainer m_InitialMeans;
00174 
00175   ParametersType m_FinalMeans;
00176 
00177   bool m_UseNonContiguousLabels;
00178 
00179   ImageRegionType m_ImageRegion;
00180 
00181   bool m_ImageRegionDefined;
00182 };
00183 } // end namespace itk
00184 
00185 #ifndef ITK_MANUAL_INSTANTIATION
00186 #include "itkScalarImageKmeansImageFilter.hxx"
00187 #endif
00188 
00189 #endif
00190