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 {
00104 template <class TInputImage, class TOutputImage, class TKernel>
00105 class ITK_EXPORT BinaryMorphologyImageFilter :
00106 public ImageToImageFilter< TInputImage, TOutputImage >
00107 {
00108 public:
00109
00111 itkStaticConstMacro(InputImageDimension, unsigned int,
00112 TInputImage::ImageDimension);
00113 itkStaticConstMacro(OutputImageDimension, unsigned int,
00114 TOutputImage::ImageDimension);
00116
00118 itkStaticConstMacro(KernelDimension, unsigned int,
00119 TKernel::NeighborhoodDimension);
00120
00122 typedef TInputImage InputImageType;
00123 typedef TOutputImage OutputImageType;
00124
00126 typedef BinaryMorphologyImageFilter Self;
00127 typedef ImageToImageFilter< InputImageType, OutputImageType> Superclass;
00128 typedef SmartPointer<Self> Pointer;
00129 typedef SmartPointer<const Self> ConstPointer;
00130
00132 itkNewMacro(Self);
00133
00135 itkTypeMacro(BinaryMorphologyImageFilter, ImageToImageFilter);
00136
00138 typedef TKernel KernelType;
00139
00141 typedef typename KernelType::ConstIterator KernelIteratorType;
00142
00144 typedef typename InputImageType::PixelType InputPixelType;
00145 typedef typename OutputImageType::PixelType OutputPixelType;
00146 typedef typename NumericTraits<InputPixelType>::RealType InputRealType;
00147 typedef typename InputImageType::OffsetType OffsetType;
00148 typedef typename InputImageType::IndexType IndexType;
00149
00150 typedef typename InputImageType::RegionType InputImageRegionType;
00151 typedef typename OutputImageType::RegionType OutputImageRegionType;
00152 typedef typename InputImageType::SizeType InputSizeType;
00153
00155 itkConceptMacro(ImageDimensionCheck,
00156 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00157 itkGetStaticConstMacro(OutputImageDimension)>));
00158
00159
00160 #if 0
00161
00162 itkConceptMacro(KernelDimensionCheck,
00163 (Concept::SameDimension<itkGetStaticConstMacro(KernelDimension),
00164 itkGetStaticConstMacro(InputImageDimension)>));
00165 #endif
00166
00168 void SetKernel( const KernelType& kernel );
00169
00171 itkGetConstReferenceMacro(Kernel, KernelType);
00172
00176 itkSetMacro(ForegroundValue, InputPixelType);
00177
00180 itkGetConstMacro(ForegroundValue, InputPixelType);
00181
00186 itkSetMacro(BackgroundValue, OutputPixelType);
00187
00192 itkGetConstMacro(BackgroundValue, OutputPixelType);
00193
00196 itkSetMacro(BoundaryToForeground, bool);
00197 itkGetConstReferenceMacro(BoundaryToForeground, bool);
00198 itkBooleanMacro(BoundaryToForeground);
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
00232 ComponentVectorConstIterator;
00233
00237 NeighborIndexContainer& GetDifferenceSet(unsigned int code)
00238 { return m_KernelDifferenceSets[code]; }
00239
00243 ComponentVectorConstIterator KernelCCVectorBegin()
00244 { return m_KernelCCVector.begin(); }
00245
00249 ComponentVectorConstIterator KernelCCVectorEnd()
00250 { return m_KernelCCVector.end(); }
00251
00255 InputSizeType GetRadius() const
00256 { return m_Radius; }
00257
00258 bool m_BoundaryToForeground;
00259
00260 private:
00261 BinaryMorphologyImageFilter(const Self&);
00262 void operator=(const Self&);
00263
00266 InputSizeType m_Radius;
00267
00269 KernelType m_Kernel;
00270
00272 InputPixelType m_ForegroundValue;
00273
00275 OutputPixelType m_BackgroundValue;
00276
00277
00278 NeighborIndexContainerContainer m_KernelDifferenceSets;
00279
00280
00281
00282
00283 std::vector< OffsetType > m_KernelCCVector;
00284 };
00285
00286 }
00287
00288 #ifndef ITK_MANUAL_INSTANTIATION
00289 #include "itkBinaryMorphologyImageFilter.txx"
00290 #endif
00291
00292 #endif
00293