00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkScalarImageKmeansImageFilter_h
00018 #define __itkScalarImageKmeansImageFilter_h
00019
00020 #include "itkImageToImageFilter.h"
00021 #include "itkImage.h"
00022 #include "itkNumericTraits.h"
00023
00024 #include "itkKdTree.h"
00025 #include "itkKdTreeBasedKmeansEstimator.h"
00026 #include "itkWeightedCentroidKdTreeGenerator.h"
00027
00028 #ifdef ITK_USE_REVIEW_STATISTICS
00029 #include "itkEuclideanDistanceMetric.h"
00030 #include "itkSampleClassifierFilter.h"
00031 #include "itkImageToListSampleAdaptor.h"
00032 #include "itkMinimumDecisionRule2.h"
00033 #else
00034 #include "itkMinimumDecisionRule.h"
00035 #include "itkEuclideanDistance.h"
00036 #include "itkSampleClassifier.h"
00037 #include "itkScalarImageToListAdaptor.h"
00038 #endif
00039
00040 #include "itkImageRegion.h"
00041 #include "itkRegionOfInterestImageFilter.h"
00042
00043 #include <vector>
00044
00045 namespace itk
00046 {
00068 template <class TInputImage >
00069 class ITK_EXPORT ScalarImageKmeansImageFilter :
00070 public ImageToImageFilter< TInputImage, Image<unsigned char,
00071 ::itk::GetImageDimension<TInputImage>::ImageDimension> >
00072 {
00073 public:
00075 itkStaticConstMacro(ImageDimension, unsigned int,
00076 TInputImage::ImageDimension);
00077
00079 typedef TInputImage InputImageType;
00080 typedef Image<unsigned char,
00081 ::itk::GetImageDimension<TInputImage>::ImageDimension> OutputImageType;
00082
00084 typedef ScalarImageKmeansImageFilter Self;
00085 typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00086 typedef SmartPointer<Self> Pointer;
00087 typedef SmartPointer<const Self> ConstPointer;
00088
00090 itkNewMacro(Self);
00091
00093 itkTypeMacro(ScalarImageKmeansImageFilter, ImageToImageFilter);
00094
00096 typedef typename InputImageType::PixelType InputPixelType;
00097 typedef typename OutputImageType::PixelType OutputPixelType;
00098
00100 typedef typename NumericTraits< InputPixelType >::RealType RealPixelType;
00101
00103 #ifdef ITK_USE_REVIEW_STATISTICS
00104 typedef itk::Statistics::ImageToListSampleAdaptor< InputImageType > AdaptorType;
00105 #else
00106 typedef itk::Statistics::ScalarImageToListAdaptor<
00107 InputImageType > AdaptorType;
00108 #endif
00109
00111 typedef typename AdaptorType::MeasurementVectorType MeasurementVectorType;
00112
00113 #ifdef ITK_USE_REVIEW_STATISTICS
00114 typedef itk::Statistics::DistanceToCentroidMembershipFunction< MeasurementVectorType > MembershipFunctionType;
00115 typedef itk::Statistics::SampleClassifierFilter< AdaptorType > ClassifierType;
00116 typedef itk::Statistics::MinimumDecisionRule2 DecisionRuleType;
00117 #else
00118 typedef itk::Statistics::EuclideanDistance< MeasurementVectorType > MembershipFunctionType;
00119 typedef itk::Statistics::SampleClassifier< AdaptorType > ClassifierType;
00120 typedef itk::MinimumDecisionRule DecisionRuleType;
00121 #endif
00122
00123 #ifdef ITK_USE_REVIEW_STATISTICS
00124 typedef typename ClassifierType::ClassLabelVectorType ClassLabelVectorType;
00125 #else
00126 typedef std::vector< unsigned int > ClassLabelVectorType;
00127 #endif
00128
00129 #ifdef ITK_USE_REVIEW_STATISTICS
00130 typedef typename ClassifierType::MembershipFunctionVectorType MembershipFunctionVectorType;
00131 typedef typename MembershipFunctionType::CentroidType MembershipFunctionOriginType;
00132 #else
00133 typedef typename MembershipFunctionType::OriginType MembershipFunctionOriginType;
00134 #endif
00135
00136 typedef typename MembershipFunctionType::Pointer MembershipFunctionPointer;
00137
00139 typedef itk::Statistics::WeightedCentroidKdTreeGenerator<
00140 AdaptorType >
00141 TreeGeneratorType;
00142 typedef typename TreeGeneratorType::KdTreeType TreeType;
00143 typedef itk::Statistics::KdTreeBasedKmeansEstimator<TreeType> EstimatorType;
00144
00145 typedef typename EstimatorType::ParametersType ParametersType;
00146
00147 typedef typename InputImageType::RegionType ImageRegionType;
00148
00149 typedef RegionOfInterestImageFilter<
00150 InputImageType,
00151 InputImageType > RegionOfInterestFilterType;
00152
00153
00155 void AddClassWithInitialMean( RealPixelType mean );
00156
00158 itkGetConstReferenceMacro( FinalMeans, ParametersType );
00159
00165 itkSetMacro( UseNonContiguousLabels, bool );
00166 itkGetConstReferenceMacro( UseNonContiguousLabels, bool );
00167 itkBooleanMacro( UseNonContiguousLabels );
00169
00171 void SetImageRegion( const ImageRegionType & region );
00172
00174 itkGetConstReferenceMacro( ImageRegion, ImageRegionType );
00175
00176 #ifdef ITK_USE_CONCEPT_CHECKING
00177
00178 itkConceptMacro(InputHasNumericTraitsCheck,
00179 (Concept::HasNumericTraits<InputPixelType>));
00180
00182 #endif
00183
00184 protected:
00185 ScalarImageKmeansImageFilter();
00186 virtual ~ScalarImageKmeansImageFilter() {}
00187 void PrintSelf(std::ostream& os, Indent indent) const;
00188
00194 void GenerateData();
00195
00196 private:
00197 ScalarImageKmeansImageFilter(const Self&);
00198 void operator=(const Self&);
00199
00200 typedef std::vector< RealPixelType > MeansContainer;
00201
00202 MeansContainer m_InitialMeans;
00203
00204 ParametersType m_FinalMeans;
00205
00206 bool m_UseNonContiguousLabels;
00207
00208 ImageRegionType m_ImageRegion;
00209
00210 bool m_ImageRegionDefined;
00211 };
00212
00213 }
00214
00215 #ifndef ITK_MANUAL_INSTANTIATION
00216 #include "itkScalarImageKmeansImageFilter.txx"
00217 #endif
00218
00219 #endif
00220