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 #ifdef ITK_USE_CONCEPT_CHECKING
00159
00161 itkConceptMacro(ImageDimensionCheck,
00162 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00163 itkGetStaticConstMacro(OutputImageDimension)>));
00164 itkConceptMacro(InputHasNumericTraitsCheck,
00165 (Concept::HasNumericTraits<InputPixelType>));
00166
00167 #if 0
00168
00170 itkConceptMacro(KernelDimensionCheck,
00171 (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00172 itkGetStaticConstMacro(InputImageDimension)>));
00173 #endif
00174
00176 #endif
00177
00179 void SetKernel( const KernelType& kernel );
00180
00182 itkGetConstReferenceMacro(Kernel, KernelType);
00183
00187 itkSetMacro(ForegroundValue, InputPixelType);
00188
00191 itkGetConstMacro(ForegroundValue, InputPixelType);
00192
00197 itkSetMacro(BackgroundValue, OutputPixelType);
00198
00203 itkGetConstMacro(BackgroundValue, OutputPixelType);
00204
00205 protected:
00206 BinaryMorphologyImageFilter();
00207 virtual ~BinaryMorphologyImageFilter(){}
00208 void PrintSelf(std::ostream& os, Indent indent) const;
00209
00213 void AnalyzeKernel();
00214
00223 void GenerateInputRequestedRegion() throw (InvalidRequestedRegionError);
00224
00225
00226 struct BorderCell
00227 {
00228 IndexType index;
00229 unsigned int code;
00230 };
00231
00232
00233 typedef std::vector< BorderCell > BorderCellContainer;
00234
00235
00236 typedef std::vector< unsigned int > NeighborIndexContainer;
00237
00238
00239 typedef std::vector<NeighborIndexContainer> NeighborIndexContainerContainer;
00240
00241
00242 typedef std::vector< OffsetType > ComponentVectorType;
00243
00244
00245 typedef typename ComponentVectorType::const_iterator ComponentVectorConstIterator;
00246
00250 NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00251 { return m_KernelDifferenceSets[code]; }
00252
00256 ComponentVectorConstIterator KernelCCVectorBegin()
00257 { return m_KernelCCVector.begin(); }
00258
00262 ComponentVectorConstIterator KernelCCVectorEnd()
00263 { return m_KernelCCVector.end(); }
00264
00268 InputSizeType GetRadius() const
00269 { return m_Radius; }
00270
00271 private:
00272 BinaryMorphologyImageFilter(const Self&);
00273 void operator=(const Self&);
00274
00277 InputSizeType m_Radius;
00278
00280 KernelType m_Kernel;
00281
00283 InputPixelType m_ForegroundValue;
00284
00286 OutputPixelType m_BackgroundValue;
00287
00288
00289 NeighborIndexContainerContainer m_KernelDifferenceSets;
00290
00291
00292
00293
00294 std::vector< OffsetType > m_KernelCCVector;
00295 };
00296
00297 }
00298
00299 #ifndef ITK_MANUAL_INSTANTIATION
00300 #include "itkBinaryMorphologyImageFilter.txx"
00301 #endif
00302
00303 #endif
00304