ITK  4.5.0
Insight Segmentation and Registration Toolkit
itkCannyEdgeDetectionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkCannyEdgeDetectionImageFilter_h
19 #define __itkCannyEdgeDetectionImageFilter_h
20 
23 #include "itkMultiplyImageFilter.h"
24 #include "itkMultiThreader.h"
25 #include "itkDerivativeOperator.h"
26 #include "itkSparseFieldLayer.h"
27 #include "itkObjectStore.h"
28 
29 namespace itk
30 {
31 template< typename TValueType >
32 class ListNode
33 {
34 public:
35  TValueType m_Value;
36 
39 };
40 
83 template< typename TInputImage, typename TOutputImage >
85  public ImageToImageFilter< TInputImage, TOutputImage >
86 {
87 public:
91 
93  typedef TInputImage InputImageType;
94  typedef TOutputImage OutputImageType;
95 
99 
101  typedef typename TInputImage::PixelType InputImagePixelType;
102  typedef typename TOutputImage::PixelType OutputImagePixelType;
103  typedef typename TInputImage::IndexType IndexType;
105 
110 
116 
121 
123  itkNewMacro(Self);
124 
126  typedef typename TOutputImage::RegionType OutputImageRegionType;
127  typedef typename TInputImage::RegionType InputImageRegionType;
128 
131 
133  itkStaticConstMacro(ImageDimension, unsigned int,
134  TInputImage::ImageDimension);
135  itkStaticConstMacro(OutputImageDimension, unsigned int,
136  TOutputImage::ImageDimension);
138 
141 
143  itkSetMacro(Variance, ArrayType);
144  itkGetConstMacro(Variance, const ArrayType);
145  itkSetMacro(MaximumError, ArrayType);
146  itkGetConstMacro(MaximumError, const ArrayType);
148 
151  void SetVariance(const typename ArrayType::ValueType v)
152  {
153  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
154  {
155  if ( m_Variance[i] != v )
156  {
157  m_Variance.Fill(v);
158  this->Modified();
159  break;
160  }
161  }
162  }
164 
167  void SetMaximumError(const typename ArrayType::ValueType v)
168  {
169  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
170  {
171  if ( m_MaximumError[i] != v )
172  {
173  m_MaximumError.Fill(v);
174  this->Modified();
175  break;
176  }
177  }
178  }
180 
190  itkSetMacro(UpperThreshold, OutputImagePixelType);
192  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
193 
194  itkSetMacro(LowerThreshold, OutputImagePixelType);
195  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
196 
198  {
199  return this->m_MultiplyImageFilter->GetOutput();
200  }
201 
209  virtual void GenerateInputRequestedRegion()
211 
212 #ifdef ITK_USE_CONCEPT_CHECKING
213  // Begin concept checking
214  itkConceptMacro( InputHasNumericTraitsCheck,
216  itkConceptMacro( OutputHasNumericTraitsCheck,
218  itkConceptMacro( SameDimensionCheck,
220  itkConceptMacro( InputIsFloatingPointCheck,
222  itkConceptMacro( OutputIsFloatingPointCheck,
224  // End concept checking
225 #endif
226 
227 protected:
229  void PrintSelf(std::ostream & os, Indent indent) const;
230 
231  void GenerateData();
232 
237 
238 private:
239  CannyEdgeDetectionImageFilter(const Self &); //purposely not implemented
240  void operator=(const Self &); //purposely not implemented
241 
243 
246  {
248  };
249 
251  void AllocateUpdateBuffer();
252 
254  void HysteresisThresholding();
255 
257  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
258 
262  void Compute2ndDerivative();
263 
272  // virtual
273  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
274 
281  outputRegionForThread, ThreadIdType threadId);
282 
288 
293  void *globalData);
294 
300 
307  outputRegionForThread, ThreadIdType threadId);
308 
314 
317 
321 
323  OutputImagePixelType m_UpperThreshold; //should be float here?
324 
326  OutputImagePixelType m_LowerThreshold; //should be float here?
327 
329  typename OutputImageType::Pointer m_UpdateBuffer1;
330 
333 
337 
345 
347 
350 
353 
356 };
357 } //end of namespace itk
358 
359 #ifndef ITK_MANUAL_INSTANTIATION
360 #include "itkCannyEdgeDetectionImageFilter.hxx"
361 #endif
362 
363 #endif
FixedArray< double, itkGetStaticConstMacro(ImageDimension) > ArrayType
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
Light weight base class for most itk classes.
static ITK_THREAD_RETURN_TYPE Compute2ndDerivativeThreaderCallback(void *arg)
ConstNeighborhoodIterator< OutputImageType, DefaultBoundaryConditionType > NeighborhoodType
void SetVariance(const typename ArrayType::ValueType v)
DerivativeOperator< OutputImagePixelType, itkGetStaticConstMacro(ImageDimension) > m_ComputeCannyEdge1stDerivativeOper
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
unsigned long SizeValueType
Definition: itkIntTypes.h:143
#define ITK_THREAD_RETURN_TYPE
ImageToImageFilter< TInputImage, TOutputImage > Superclass
void Fill(const ValueType &)
GaussianImageFilterType::Pointer m_GaussianFilter
static ITK_THREAD_RETURN_TYPE Compute2ndDerivativePosThreaderCallback(void *arg)
void PrintSelf(std::ostream &os, Indent indent) const
DiscreteGaussianImageFilter< InputImageType, OutputImageType > GaussianImageFilterType
MultiplyImageFilterType::Pointer m_MultiplyImageFilter
DerivativeOperator< OutputImagePixelType, itkGetStaticConstMacro(ImageDimension) > m_ComputeCannyEdge2ndDerivativeOper
virtual void GenerateInputRequestedRegion()
void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput)
void ThreadedCompute2ndDerivative(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId)
ZeroFluxNeumannBoundaryCondition< OutputImageType > DefaultBoundaryConditionType
OutputImageType::PixelType OutputImagePixelType
virtual void Modified() const
MultiplyImageFilter< OutputImageType, OutputImageType, OutputImageType > MultiplyImageFilterType
OutputImagePixelType ComputeCannyEdge(const NeighborhoodType &it, void *globalData)
void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId)
Base class for filters that take an image as input and produce an image as output.
OutputImageType::RegionType OutputImageRegionType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Pixel-wise multiplication of two images.
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver...
#define itkConceptMacro(name, concept)
A specialized memory management object for allocating and destroying contiguous blocks of objects...
void SetMaximumError(const typename ArrayType::ValueType v)
Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian...
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
This filter is an implementation of a Canny edge detector for scalar-valued images. Based on John Canny&#39;s paper &quot;A Computational Approach to Edge Detection&quot;(IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. PAMI-8, No.6, November 1986), there are four major steps used in the edge-detection scheme: (1) Smooth the input image with Gaussian filter. (2) Calculate the second directional derivatives of the smoothed image. (3) Non-Maximum Suppression: the zero-crossings of 2nd derivative are found, and the sign of third derivative is used to find the correct extrema. (4) The hysteresis thresholding is applied to the gradient magnitude (multiplied with zero-crossings) of the smoothed image to find and link edges.