00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkBinaryMorphologyImageFilter_h
00018 #define __itkBinaryMorphologyImageFilter_h
00019
00020 #include <vector>
00021 #include <queue>
00022 #include "itkImageToImageFilter.h"
00023 #include "itkImage.h"
00024 #include "itkNumericTraits.h"
00025 #include "itkNeighborhoodIterator.h"
00026 #include "itkConstNeighborhoodIterator.h"
00027 #include "itkNeighborhood.h"
00028 #include "itkImageBoundaryCondition.h"
00029 #include "itkImageRegionIterator.h"
00030 #include "itkConceptChecking.h"
00031
00032 namespace itk
00033 {
00107 template <class TInputImage, class TOutputImage, class TKernel>
00108 class ITK_EXPORT BinaryMorphologyImageFilter :
00109 public ImageToImageFilter< TInputImage, TOutputImage >
00110 {
00111 public:
00112
00114 itkStaticConstMacro(InputImageDimension, unsigned int,
00115 TInputImage::ImageDimension);
00116 itkStaticConstMacro(OutputImageDimension, unsigned int,
00117 TOutputImage::ImageDimension);
00119
00121 itkStaticConstMacro(KernelDimension, unsigned int,
00122 TKernel::NeighborhoodDimension);
00123
00125 typedef TInputImage InputImageType;
00126 typedef TOutputImage OutputImageType;
00127
00129 typedef BinaryMorphologyImageFilter Self;
00130 typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00131 typedef SmartPointer<Self> Pointer;
00132 typedef SmartPointer<const Self> ConstPointer;
00133
00135 itkNewMacro(Self);
00136
00138 itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00139
00141 typedef TKernel KernelType;
00142
00144 typedef typename KernelType::ConstIterator KernelIteratorType;
00145
00147 typedef typename InputImageType::PixelType InputPixelType;
00148 typedef typename OutputImageType::PixelType OutputPixelType;
00149 typedef typename NumericTraits<InputPixelType>::RealType InputRealType;
00150 typedef typename InputImageType::OffsetType OffsetType;
00151 typedef typename InputImageType::IndexType IndexType;
00152
00153 typedef typename InputImageType::RegionType InputImageRegionType;
00154 typedef typename OutputImageType::RegionType OutputImageRegionType;
00155 typedef typename InputImageType::SizeType InputSizeType;
00156
00158 itkConceptMacro(ImageDimensionCheck,
00159 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00160 itkGetStaticConstMacro(OutputImageDimension)>));
00161
00162
00163 #if 0
00164
00165 itkConceptMacro(KernelDimensionCheck,
00166 (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00167 itkGetStaticConstMacro(InputImageDimension)>));
00168 #endif
00169
00171 void SetKernel( const KernelType& kernel );
00172
00174 itkGetConstReferenceMacro(Kernel, KernelType);
00175
00179 itkSetMacro(ForegroundValue, InputPixelType);
00180
00183 itkGetConstMacro(ForegroundValue, InputPixelType);
00184
00189 itkSetMacro(BackgroundValue, OutputPixelType);
00190
00195 itkGetConstMacro(BackgroundValue, OutputPixelType);
00196
00199 itkSetMacro(BoundaryToForeground, bool);
00200 itkGetConstReferenceMacro(BoundaryToForeground, bool);
00201 itkBooleanMacro(BoundaryToForeground);
00203
00204 protected:
00205 BinaryMorphologyImageFilter();
00206 virtual ~BinaryMorphologyImageFilter(){}
00207 void PrintSelf(std::ostream& os, Indent indent) const;
00208
00212 void AnalyzeKernel();
00213
00222 void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00223
00224
00225 typedef std::vector< OffsetType > NeighborIndexContainer;
00226
00227
00228 typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00229
00230
00231 typedef std::vector< OffsetType > ComponentVectorType;
00232
00233
00234 typedef typename ComponentVectorType::const_iterator
00235 ComponentVectorConstIterator;
00236
00240 NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00241 { return m_KernelDifferenceSets[code]; }
00242
00246 ComponentVectorConstIterator KernelCCVectorBegin()
00247 { return m_KernelCCVector.begin(); }
00248
00252 ComponentVectorConstIterator KernelCCVectorEnd()
00253 { return m_KernelCCVector.end(); }
00254
00258 InputSizeType GetRadius() const
00259 { return m_Radius; }
00260
00261 bool m_BoundaryToForeground;
00262
00263 private:
00264 BinaryMorphologyImageFilter(const Self&);
00265 void operator=(const Self&);
00266
00269 InputSizeType m_Radius;
00270
00272 KernelType m_Kernel;
00273
00275 InputPixelType m_ForegroundValue;
00276
00278 OutputPixelType m_BackgroundValue;
00279
00280
00281 NeighborIndexContainerContainer m_KernelDifferenceSets;
00282
00283
00284
00285
00286 std::vector< OffsetType > m_KernelCCVector;
00287 };
00288
00289 }
00290
00291 #ifndef ITK_MANUAL_INSTANTIATION
00292 #include "itkBinaryMorphologyImageFilter.txx"
00293 #endif
00294
00295 #endif
00296