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:
00113 itkStaticConstMacro(InputImageDimension, unsigned int,
00114 TInputImage::ImageDimension);
00115 itkStaticConstMacro(OutputImageDimension, unsigned int,
00116 TOutputImage::ImageDimension);
00117
00119 itkStaticConstMacro(KernelDimension, unsigned int,
00120 TKernel::NeighborhoodDimension);
00121
00123 typedef TInputImage InputImageType;
00124 typedef TOutputImage OutputImageType;
00125
00127 typedef BinaryMorphologyImageFilter Self;
00128 typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00129 typedef SmartPointer<Self> Pointer;
00130 typedef SmartPointer<const Self> ConstPointer;
00131
00133 itkNewMacro(Self);
00134
00136 itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00137
00139 typedef TKernel KernelType;
00140
00142 typedef typename KernelType::ConstIterator KernelIteratorType ;
00143
00145 typedef typename InputImageType::PixelType InputPixelType;
00146 typedef typename OutputImageType::PixelType OutputPixelType;
00147 typedef typename NumericTraits<InputPixelType>::RealType InputRealType;
00148 typedef typename InputImageType::OffsetType OffsetType;
00149 typedef typename InputImageType::IndexType IndexType;
00150
00151 typedef typename InputImageType::RegionType InputImageRegionType;
00152 typedef typename OutputImageType::RegionType OutputImageRegionType;
00153 typedef typename InputImageType::SizeType InputSizeType;
00154
00156 itkConceptMacro(ImageDimensionCheck,
00157 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00158 itkGetStaticConstMacro(OutputImageDimension)>));
00159
00160
00161 #if 0
00162
00163 itkConceptMacro(KernelDimensionCheck,
00164 (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00165 itkGetStaticConstMacro(InputImageDimension)>));
00166 #endif
00167
00169 void SetKernel( const KernelType& kernel );
00170
00172 itkGetConstReferenceMacro(Kernel, KernelType);
00173
00177 itkSetMacro(ForegroundValue, InputPixelType);
00178
00181 itkGetConstMacro(ForegroundValue, InputPixelType);
00182
00187 itkSetMacro(BackgroundValue, OutputPixelType);
00188
00193 itkGetConstMacro(BackgroundValue, OutputPixelType);
00194
00195 protected:
00196 BinaryMorphologyImageFilter();
00197 virtual ~BinaryMorphologyImageFilter(){}
00198 void PrintSelf(std::ostream& os, Indent indent) const;
00199
00203 void AnalyzeKernel();
00204
00213 void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00214
00215
00216 struct BorderCell
00217 {
00218 IndexType index;
00219 unsigned int code;
00220 };
00221
00222
00223 typedef std::vector< BorderCell > BorderCellContainer;
00224
00225
00226 typedef std::vector< unsigned int > NeighborIndexContainer;
00227
00228
00229 typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00230
00231
00232 typedef std::vector< OffsetType > ComponentVectorType;
00233
00234
00235 typedef typename ComponentVectorType::const_iterator 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 private:
00262 BinaryMorphologyImageFilter(const Self&);
00263 void operator=(const Self&);
00264
00267 InputSizeType m_Radius;
00268
00270 KernelType m_Kernel;
00271
00273 InputPixelType m_ForegroundValue;
00274
00276 OutputPixelType m_BackgroundValue;
00277
00278
00279 NeighborIndexContainerContainer m_KernelDifferenceSets;
00280
00281
00282
00283
00284 std::vector< OffsetType > m_KernelCCVector;
00285 };
00286
00287 }
00288
00289 #ifndef ITK_MANUAL_INSTANTIATION
00290 #include "itkBinaryMorphologyImageFilter.txx"
00291 #endif
00292
00293 #endif