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 #include "itkMinimumDecisionRule.h"
00029 #include "itkEuclideanDistance.h"
00030 #include "itkSampleClassifier.h"
00031
00032 #include "itkScalarImageToListAdaptor.h"
00033
00034 #include <vector>
00035
00036 namespace itk
00037 {
00059 template <class TInputImage >
00060 class ITK_EXPORT ScalarImageKmeansImageFilter :
00061 public ImageToImageFilter< TInputImage, Image<unsigned char,
00062 ::itk::GetImageDimension<TInputImage>::ImageDimension> >
00063 {
00064 public:
00066 itkStaticConstMacro(ImageDimension, unsigned int,
00067 TInputImage::ImageDimension);
00068
00070 typedef TInputImage InputImageType;
00071 typedef Image<unsigned char,
00072 ::itk::GetImageDimension<TInputImage>::ImageDimension> OutputImageType;
00073
00075 typedef ScalarImageKmeansImageFilter Self;
00076 typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00077 typedef SmartPointer<Self> Pointer;
00078 typedef SmartPointer<const Self> ConstPointer;
00079
00081 itkNewMacro(Self);
00082
00084 itkTypeMacro(ScalarImageKmeansImageFilter, ImageToImageFilter);
00085
00087 typedef typename InputImageType::PixelType InputPixelType;
00088 typedef typename OutputImageType::PixelType OutputPixelType;
00089
00091 typedef typename NumericTraits< InputPixelType >::RealType RealPixelType;
00092
00094 typedef itk::Statistics::ScalarImageToListAdaptor<
00095 InputImageType > AdaptorType;
00096
00098 typedef typename AdaptorType::MeasurementVectorType MeasurementVectorType;
00099
00101 typedef itk::Statistics::WeightedCentroidKdTreeGenerator<
00102 AdaptorType >
00103 TreeGeneratorType;
00104 typedef typename TreeGeneratorType::KdTreeType TreeType;
00105 typedef itk::Statistics::KdTreeBasedKmeansEstimator<TreeType> EstimatorType;
00106
00107 typedef typename EstimatorType::ParametersType ParametersType;
00108
00109
00111 void AddClassWithInitialMean( RealPixelType mean );
00112
00114 itkGetConstReferenceMacro( FinalMeans, ParametersType );
00115
00121 itkSetMacro( UseNonContiguousLabels, bool );
00122 itkGetConstReferenceMacro( UseNonContiguousLabels, bool );
00123 itkBooleanMacro( UseNonContiguousLabels );
00124
00125 protected:
00126 ScalarImageKmeansImageFilter();
00127 virtual ~ScalarImageKmeansImageFilter() {}
00128 void PrintSelf(std::ostream& os, Indent indent) const;
00129
00135 void GenerateData();
00136
00137 private:
00138 ScalarImageKmeansImageFilter(const Self&);
00139 void operator=(const Self&);
00140
00141 typedef std::vector< RealPixelType > MeansContainer;
00142
00143 MeansContainer m_InitialMeans;
00144
00145 ParametersType m_FinalMeans;
00146
00147 bool m_UseNonContiguousLabels;
00148 };
00149
00150 }
00151
00152 #ifndef ITK_MANUAL_INSTANTIATION
00153 #include "itkScalarImageKmeansImageFilter.txx"
00154 #endif
00155
00156 #endif