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 #include "itkImageRegion.h"
00034 #include "itkRegionOfInterestImageFilter.h"
00035
00036 #include <vector>
00037
00038 namespace itk
00039 {
00061 template <class TInputImage >
00062 class ITK_EXPORT ScalarImageKmeansImageFilter :
00063 public ImageToImageFilter< TInputImage, Image<unsigned char,
00064 ::itk::GetImageDimension<TInputImage>::ImageDimension> >
00065 {
00066 public:
00068 itkStaticConstMacro(ImageDimension, unsigned int,
00069 TInputImage::ImageDimension);
00070
00072 typedef TInputImage InputImageType;
00073 typedef Image<unsigned char,
00074 ::itk::GetImageDimension<TInputImage>::ImageDimension> 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::ScalarImageToListAdaptor<
00097 InputImageType > AdaptorType;
00098
00100 typedef typename AdaptorType::MeasurementVectorType MeasurementVectorType;
00101
00103 typedef itk::Statistics::WeightedCentroidKdTreeGenerator<
00104 AdaptorType >
00105 TreeGeneratorType;
00106 typedef typename TreeGeneratorType::KdTreeType TreeType;
00107 typedef itk::Statistics::KdTreeBasedKmeansEstimator<TreeType> EstimatorType;
00108
00109 typedef typename EstimatorType::ParametersType ParametersType;
00110
00111 typedef typename InputImageType::RegionType ImageRegionType;
00112
00113 typedef RegionOfInterestImageFilter<
00114 InputImageType,
00115 InputImageType > RegionOfInterestFilterType;
00116
00117
00119 void AddClassWithInitialMean( RealPixelType mean );
00120
00122 itkGetConstReferenceMacro( FinalMeans, ParametersType );
00123
00129 itkSetMacro( UseNonContiguousLabels, bool );
00130 itkGetConstReferenceMacro( UseNonContiguousLabels, bool );
00131 itkBooleanMacro( UseNonContiguousLabels );
00132
00134 void SetImageRegion( const ImageRegionType & region );
00135
00137 itkGetConstReferenceMacro( ImageRegion, ImageRegionType );
00138
00139 protected:
00140 ScalarImageKmeansImageFilter();
00141 virtual ~ScalarImageKmeansImageFilter() {}
00142 void PrintSelf(std::ostream& os, Indent indent) const;
00143
00149 void GenerateData();
00150
00151 private:
00152 ScalarImageKmeansImageFilter(const Self&);
00153 void operator=(const Self&);
00154
00155 typedef std::vector< RealPixelType > MeansContainer;
00156
00157 MeansContainer m_InitialMeans;
00158
00159 ParametersType m_FinalMeans;
00160
00161 bool m_UseNonContiguousLabels;
00162
00163 ImageRegionType m_ImageRegion;
00164
00165 bool m_ImageRegionDefined;
00166 };
00167
00168 }
00169
00170 #ifndef ITK_MANUAL_INSTANTIATION
00171 #include "itkScalarImageKmeansImageFilter.txx"
00172 #endif
00173
00174 #endif