Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkCannyEdgeDetectionImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkCannyEdgeDetectionImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/01/12 21:06:18 $
00007   Version:   $Revision: 1.18 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkCannyEdgeDetectionImageFilter_h
00018 #define __itkCannyEdgeDetectionImageFilter_h
00019 
00020 #include "itkImageToImageFilter.h"
00021 #include "itkImage.h"
00022 #include "itkFixedArray.h"
00023 #include "itkConstNeighborhoodIterator.h"
00024 #include "itkZeroFluxNeumannBoundaryCondition.h"
00025 #include "itkMultiThreader.h"
00026 #include "itkDerivativeOperator.h"
00027 #include "itkSparseFieldLayer.h"
00028 #include "itkObjectStore.h"
00029 
00030 
00031 namespace itk
00032 {
00033 
00034 
00035 template <class TValueType>
00036 class ListNode
00037 {
00038 public:
00039   TValueType m_Value;
00040   ListNode *Next;
00041   ListNode *Previous;
00042 };
00043 
00044 
00086 template<class TInputImage, class TOutputImage>
00087 class ITK_EXPORT CannyEdgeDetectionImageFilter
00088   : public ImageToImageFilter<TInputImage, TOutputImage>
00089 {
00090 public:
00092   typedef CannyEdgeDetectionImageFilter    Self;
00093   typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
00094    
00096   typedef TInputImage  InputImageType;
00097   typedef TOutputImage OutputImageType;
00098       
00100   typedef SmartPointer<Self>  Pointer;
00101   typedef SmartPointer<const Self>  ConstPointer;
00102 
00104   typedef typename TInputImage::PixelType  InputImagePixelType;
00105   typedef typename TOutputImage::PixelType  OutputImagePixelType;
00106   typedef typename TInputImage::IndexType   IndexType;
00107 
00110   typedef ZeroFluxNeumannBoundaryCondition<OutputImageType>
00111   DefaultBoundaryConditionType;
00112 
00116   typedef ConstNeighborhoodIterator<OutputImageType,
00117                                     DefaultBoundaryConditionType> NeighborhoodType;
00118 
00119   typedef ListNode<IndexType> ListNodeType;
00120   typedef ObjectStore<ListNodeType> ListNodeStorageType;
00121   typedef SparseFieldLayer<ListNodeType> ListType;
00122   typedef typename ListType::Pointer ListPointerType;
00123 
00125   itkNewMacro(Self);  
00126     
00128   typedef typename TOutputImage::RegionType OutputImageRegionType;
00129     
00131   itkTypeMacro(CannyEdgeDetectionImageFilter, ImageToImageFilter);
00132   
00134   itkStaticConstMacro(ImageDimension, unsigned int,
00135                       TInputImage::ImageDimension);
00136   
00138   typedef FixedArray<double, itkGetStaticConstMacro(ImageDimension)> ArrayType;
00139 
00141   itkSetMacro(Variance, ArrayType);
00142   itkGetMacro(Variance, const ArrayType);
00143   itkSetMacro(MaximumError, ArrayType);
00144   itkGetMacro(MaximumError, const ArrayType);
00145   
00148   void SetVariance(const typename ArrayType::ValueType v)
00149   {
00150     for (unsigned int i=0; i < TInputImage::ImageDimension; i++)
00151       {
00152       if (m_Variance[i] != v)
00153         {
00154         m_Variance.Fill(v);
00155         this->Modified();
00156         break;
00157         }
00158       }
00159   }
00160   
00163   void SetMaximumError(const typename ArrayType::ValueType v)
00164   {
00165     for (unsigned int i=0; i < TInputImage::ImageDimension; i++)
00166       {
00167       if (m_Variance[i] != v)
00168         {
00169         m_MaximumError.Fill(v);
00170         this->Modified();
00171         break;
00172         }
00173       }
00174   }
00175   
00176   /* Set the Threshold value for detected edges. */
00177   itkSetMacro(Threshold, OutputImagePixelType );
00178   itkGetMacro(Threshold, OutputImagePixelType);
00179 
00181   //itkSetMacro(UpperThreshold, OutputImagePixelType );
00182   //itkGetMacro(UpperThreshold, OutputImagePixelType);
00183 
00184   //itkSetMacro(LowerThreshold, OutputImagePixelType );
00185   //itkGetMacro(LowerThreshold, OutputImagePixelType);
00186 
00187   /* Set the Thresholdvalue for detected edges. */
00188   itkSetMacro(OutsideValue, OutputImagePixelType);
00189   itkGetMacro(OutsideValue, OutputImagePixelType);
00190   
00198   virtual void GenerateInputRequestedRegion() throw(InvalidRequestedRegionError);
00199 
00200 protected:
00201   CannyEdgeDetectionImageFilter();
00202   CannyEdgeDetectionImageFilter(const Self&) {}
00203   void PrintSelf(std::ostream& os, Indent indent) const;
00204 
00205   void GenerateData();
00206 
00207 private:
00208   virtual ~CannyEdgeDetectionImageFilter(){};
00209 
00211   struct CannyThreadStruct
00212   {
00213     CannyEdgeDetectionImageFilter *Filter;
00214   };
00215 
00217   void AllocateUpdateBuffer();
00218 
00220   void HysteresisThresholding();
00221 
00223   void FollowEdge(IndexType index);
00224 
00226   bool InBounds(IndexType index);
00227   
00228 
00232   void Compute2ndDerivative();
00233 
00242   //  virtual
00243   //  int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
00244 
00250   void ThreadedCompute2ndDerivative(const OutputImageRegionType&
00251                                     outputRegionForThread, int threadId);
00252 
00256   static ITK_THREAD_RETURN_TYPE
00257   Compute2ndDerivativeThreaderCallback( void * arg );
00258 
00262   OutputImagePixelType ComputeCannyEdge(const NeighborhoodType &it,
00263                                         void *globalData );
00264 
00269   void Compute2ndDerivativePos();
00270 
00276   void ThreadedCompute2ndDerivativePos(const OutputImageRegionType&
00277                                        outputRegionForThread, int threadId);
00278 
00282   static ITK_THREAD_RETURN_TYPE
00283   Compute2ndDerivativePosThreaderCallback( void *arg );
00284 
00286   ArrayType m_Variance;
00287 
00290   ArrayType m_MaximumError;
00291 
00293   OutputImagePixelType m_UpperThreshold;  //should be float here?
00294   
00296   OutputImagePixelType m_LowerThreshold; //should be float here?
00297 
00299   OutputImagePixelType m_Threshold;
00300 
00302   OutputImagePixelType m_OutsideValue;
00303 
00305   typename OutputImageType::Pointer  m_UpdateBuffer;
00306   typename OutputImageType::Pointer  m_UpdateBuffer1;
00307 
00310   DerivativeOperator<OutputImagePixelType,itkGetStaticConstMacro(ImageDimension)>
00311   m_ComputeCannyEdge1stDerivativeOper;
00312   DerivativeOperator<OutputImagePixelType,itkGetStaticConstMacro(ImageDimension)>
00313   m_ComputeCannyEdge2ndDerivativeOper;
00314 
00315   std::slice  m_ComputeCannyEdgeSlice[ImageDimension];
00316 
00317   unsigned long m_Stride[ImageDimension];
00318   unsigned long m_Center;
00319 
00320   typename ListNodeStorageType::Pointer m_NodeStore;
00321   ListPointerType m_NodeList;
00322 
00323 };
00324 
00325 } //end of namespace itk
00326 
00327 #ifndef ITK_MANUAL_INSTANTIATION
00328 #include "itkCannyEdgeDetectionImageFilter.txx"
00329 #endif
00330   
00331 #endif
00332 

Generated at Tue Mar 29 23:48:02 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000