ITK  4.10.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 #include "itkMath.h"
29 
30 namespace itk
31 {
32 template< typename TValue >
33 class ListNode
34 {
35 public:
36  TValue m_Value;
37 
40 };
41 
86 template< typename TInputImage, typename TOutputImage >
88  public ImageToImageFilter< TInputImage, TOutputImage >
89 {
90 public:
94 
96  typedef TInputImage InputImageType;
97  typedef TOutputImage OutputImageType;
98 
102 
104  typedef typename TInputImage::PixelType InputImagePixelType;
105  typedef typename TOutputImage::PixelType OutputImagePixelType;
106  typedef typename TInputImage::IndexType IndexType;
108 
113 
117  typedef ConstNeighborhoodIterator< OutputImageType,
119 
124 
126  itkNewMacro(Self);
127 
129  typedef typename TOutputImage::RegionType OutputImageRegionType;
130  typedef typename TInputImage::RegionType InputImageRegionType;
131 
134 
136  itkStaticConstMacro(ImageDimension, unsigned int,
137  TInputImage::ImageDimension);
138  itkStaticConstMacro(OutputImageDimension, unsigned int,
139  TOutputImage::ImageDimension);
141 
144 
146  itkSetMacro(Variance, ArrayType);
147  itkGetConstMacro(Variance, const ArrayType);
148  itkSetMacro(MaximumError, ArrayType);
149  itkGetConstMacro(MaximumError, const ArrayType);
151 
154  void SetVariance(const typename ArrayType::ValueType v)
155  {
156  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
157  {
158  if ( Math::NotExactlyEquals(m_Variance[i], v) )
159  {
160  m_Variance.Fill(v);
161  this->Modified();
162  break;
163  }
164  }
165  }
167 
170  void SetMaximumError(const typename ArrayType::ValueType v)
171  {
172  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
173  {
174  if ( Math::NotExactlyEquals(m_MaximumError[i], v) )
175  {
176  m_MaximumError.Fill(v);
177  this->Modified();
178  break;
179  }
180  }
181  }
183 
194  itkSetMacro(UpperThreshold, OutputImagePixelType);
195  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
196 
197  itkSetMacro(LowerThreshold, OutputImagePixelType);
198  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
199 
200  OutputImageType * GetNonMaximumSuppressionImage()
201  {
202  return this->m_MultiplyImageFilter->GetOutput();
203  }
204 
212  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
213 
214 #ifdef ITK_USE_CONCEPT_CHECKING
215  // Begin concept checking
216  itkConceptMacro( InputHasNumericTraitsCheck,
218  itkConceptMacro( OutputHasNumericTraitsCheck,
220  itkConceptMacro( SameDimensionCheck,
222  itkConceptMacro( InputIsFloatingPointCheck,
224  itkConceptMacro( OutputIsFloatingPointCheck,
226  // End concept checking
227 #endif
228 
229 protected:
231  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
232 
233  void GenerateData() ITK_OVERRIDE;
234 
237  typedef MultiplyImageFilter< OutputImageType,
238  OutputImageType, OutputImageType > MultiplyImageFilterType;
239 
240 private:
241  CannyEdgeDetectionImageFilter(const Self &) ITK_DELETE_FUNCTION;
242  void operator=(const Self &) ITK_DELETE_FUNCTION;
243 
245 
248  {
250  };
251 
253  void AllocateUpdateBuffer();
254 
256  void HysteresisThresholding();
257 
259  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
260 
264  void Compute2ndDerivative();
265 
274  // virtual
275  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
276 
282  void ThreadedCompute2ndDerivative(const OutputImageRegionType &
283  outputRegionForThread, ThreadIdType threadId);
284 
289  Compute2ndDerivativeThreaderCallback(void *arg);
290 
294  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
295  void *globalData);
296 
301  void Compute2ndDerivativePos();
302 
308  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &
309  outputRegionForThread, ThreadIdType threadId);
310 
315  Compute2ndDerivativePosThreaderCallback(void *arg);
316 
318  ArrayType m_Variance;
319 
322  ArrayType m_MaximumError;
323 
325  OutputImagePixelType m_UpperThreshold; //should be float here?
326 
328  OutputImagePixelType m_LowerThreshold; //should be float here?
329 
331  typename OutputImageType::Pointer m_UpdateBuffer1;
332 
335 
339 
347 
348  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
349 
350  SizeValueType m_Stride[ImageDimension];
351  SizeValueType m_Center;
352 
354  ListPointerType m_NodeList;
355 
356  OutputImageType *m_OutputImage;
357 };
358 } //end of namespace itk
359 
360 #ifndef ITK_MANUAL_INSTANTIATION
361 #include "itkCannyEdgeDetectionImageFilter.hxx"
362 #endif
363 
364 #endif
FixedArray< double, itkGetStaticConstMacro(ImageDimension) > ArrayType
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
ConstNeighborhoodIterator< OutputImageType, DefaultBoundaryConditionType > NeighborhoodType
void SetVariance(const typename ArrayType::ValueType v)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes...
Definition: itkArray.h:30
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
GaussianImageFilterType::Pointer m_GaussianFilter
DiscreteGaussianImageFilter< InputImageType, OutputImageType > GaussianImageFilterType
MultiplyImageFilterType::Pointer m_MultiplyImageFilter
DerivativeOperator< OutputImagePixelType, itkGetStaticConstMacro(ImageDimension) > m_ComputeCannyEdge2ndDerivativeOper
ZeroFluxNeumannBoundaryCondition< OutputImageType > DefaultBoundaryConditionType
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:723
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
MultiplyImageFilter< OutputImageType, OutputImageType, OutputImageType > MultiplyImageFilterType
Base class for filters that take an image as input and produce an image as output.
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...
This filter is an implementation of a Canny edge detector for scalar-valued images.