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
00197 itkSetMacro(BoundaryIsForeground, bool);
00198 itkGetConstReferenceMacro(BoundaryIsForeground, bool);
00199 itkBooleanMacro(BoundaryIsForeground);
00200
00201 protected:
00202 BinaryMorphologyImageFilter();
00203 virtual ~BinaryMorphologyImageFilter(){}
00204 void PrintSelf(std::ostream& os, Indent indent) const;
00205
00209 void AnalyzeKernel();
00210
00219 void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00220
00221
00222 typedef std::vector< OffsetType > NeighborIndexContainer;
00223
00224
00225 typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00226
00227
00228 typedef std::vector< OffsetType > ComponentVectorType;
00229
00230
00231 typedef typename ComponentVectorType::const_iterator ComponentVectorConstIterator;
00232
00236 NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00237 { return m_KernelDifferenceSets[code]; }
00238
00242 ComponentVectorConstIterator KernelCCVectorBegin()
00243 { return m_KernelCCVector.begin(); }
00244
00248 ComponentVectorConstIterator KernelCCVectorEnd()
00249 { return m_KernelCCVector.end(); }
00250
00254 InputSizeType GetRadius() const
00255 { return m_Radius; }
00256
00257 bool m_BoundaryIsForeground;
00258
00259 private:
00260 BinaryMorphologyImageFilter(const Self&);
00261 void operator=(const Self&);
00262
00265 InputSizeType m_Radius;
00266
00268 KernelType m_Kernel;
00269
00271 InputPixelType m_ForegroundValue;
00272
00274 OutputPixelType m_BackgroundValue;
00275
00276
00277 NeighborIndexContainerContainer m_KernelDifferenceSets;
00278
00279
00280
00281
00282 std::vector< OffsetType > m_KernelCCVector;
00283 };
00284
00285 }
00286
00287 #ifndef ITK_MANUAL_INSTANTIATION
00288 #include "itkBinaryMorphologyImageFilter.txx"
00289 #endif
00290
00291 #endif
00292