00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 m_Variance.Fill(v);
00151 }
00152
00155
void SetMaximumError(
const typename ArrayType::ValueType v)
00156 {
00157 m_MaximumError.Fill(v);
00158 }
00159
00160
00161
itkSetMacro(Threshold, OutputImagePixelType );
00162
itkGetMacro(Threshold, OutputImagePixelType);
00163
00165
00166
00167
00168
00169
00170
00171
00172
itkSetMacro(OutsideValue, OutputImagePixelType);
00173
itkGetMacro(OutsideValue, OutputImagePixelType);
00174
00182
virtual void GenerateInputRequestedRegion() throw(
InvalidRequestedRegionError);
00183
00184 protected:
00185 CannyEdgeDetectionImageFilter();
00186 CannyEdgeDetectionImageFilter(const Self&) {}
00187 void PrintSelf(std::ostream& os,
Indent indent)
const;
00188
00189
void GenerateData();
00190
00191
private:
00192
virtual ~CannyEdgeDetectionImageFilter(){};
00193
00195
struct CannyThreadStruct
00196 {
00197 CannyEdgeDetectionImageFilter *Filter;
00198 };
00199
00201
void AllocateUpdateBuffer();
00202
00204
void HysteresisThresholding();
00205
00207
void FollowEdge(IndexType index);
00208
00210
bool InBounds(IndexType index);
00211
00212
00216
void Compute2ndDerivative();
00217
00226
00227
00228
00234
void ThreadedCompute2ndDerivative(
const OutputImageRegionType&
00235 outputRegionForThread,
int threadId);
00236
00240
static ITK_THREAD_RETURN_TYPE
00241 Compute2ndDerivativeThreaderCallback(
void * arg );
00242
00246 OutputImagePixelType ComputeCannyEdge(
const NeighborhoodType &it,
00247
void *globalData );
00248
00253
void Compute2ndDerivativePos();
00254
00260
void ThreadedCompute2ndDerivativePos(
const OutputImageRegionType&
00261 outputRegionForThread,
int threadId);
00262
00266
static ITK_THREAD_RETURN_TYPE
00267 Compute2ndDerivativePosThreaderCallback(
void *arg );
00268
00270 ArrayType m_Variance;
00271
00274 ArrayType m_MaximumError;
00275
00277 OutputImagePixelType m_UpperThreshold;
00278
00280 OutputImagePixelType m_LowerThreshold;
00281
00283 OutputImagePixelType m_Threshold;
00284
00286 OutputImagePixelType m_OutsideValue;
00287
00289
typename OutputImageType::Pointer m_UpdateBuffer;
00290
typename OutputImageType::Pointer m_UpdateBuffer1;
00291
00294 DerivativeOperator<OutputImagePixelType,itkGetStaticConstMacro(ImageDimension)>
00295 m_ComputeCannyEdge1stDerivativeOper;
00296 DerivativeOperator<OutputImagePixelType,itkGetStaticConstMacro(ImageDimension)>
00297 m_ComputeCannyEdge2ndDerivativeOper;
00298
00299 std::slice m_ComputeCannyEdgeSlice[ImageDimension];
00300
00301
unsigned long m_Stride[ImageDimension];
00302
unsigned long m_Center;
00303
00304
typename ListNodeStorageType::Pointer m_NodeStore;
00305 ListPointerType m_NodeList;
00306
00307 };
00308
00309 }
00310
00311
#ifndef ITK_MANUAL_INSTANTIATION
00312
#include "itkCannyEdgeDetectionImageFilter.txx"
00313
#endif
00314
00315
#endif
00316