ITK  4.11.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 ITK_TEMPLATE_EXPORT ListNode
34 {
35 public:
36  TValue m_Value;
37 
40 };
41 
86 template< typename TInputImage, typename TOutputImage >
87 class ITK_TEMPLATE_EXPORT CannyEdgeDetectionImageFilter:
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 
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 
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 
235  typedef DiscreteGaussianImageFilter< InputImageType, OutputImageType >
238  OutputImageType, OutputImageType > MultiplyImageFilterType;
239 
240 private:
241  ITK_DISALLOW_COPY_AND_ASSIGN(CannyEdgeDetectionImageFilter);
242 
243  virtual ~CannyEdgeDetectionImageFilter(){}
244 
247  {
249  };
250 
252  void AllocateUpdateBuffer();
253 
255  void HysteresisThresholding();
256 
258  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
259 
263  void Compute2ndDerivative();
264 
273  // virtual
274  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
275 
281  void ThreadedCompute2ndDerivative(const OutputImageRegionType &
282  outputRegionForThread, ThreadIdType threadId);
283 
288  Compute2ndDerivativeThreaderCallback(void *arg);
289 
293  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
294  void *globalData);
295 
300  void Compute2ndDerivativePos();
301 
307  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &
308  outputRegionForThread, ThreadIdType threadId);
309 
314  Compute2ndDerivativePosThreaderCallback(void *arg);
315 
318 
322 
324  OutputImagePixelType m_UpperThreshold; //should be float here?
325 
327  OutputImagePixelType m_LowerThreshold; //should be float here?
328 
330  typename OutputImageType::Pointer m_UpdateBuffer1;
331 
334 
338 
346 
347  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
348 
349  SizeValueType m_Stride[ImageDimension];
351 
354 
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.
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
GaussianImageFilterType::Pointer m_GaussianFilter
MultiplyImageFilterType::Pointer m_MultiplyImageFilter
DerivativeOperator< OutputImagePixelType, itkGetStaticConstMacro(ImageDimension) > m_ComputeCannyEdge2ndDerivativeOper
ZeroFluxNeumannBoundaryCondition< OutputImageType > DefaultBoundaryConditionType
OutputImageType::PixelType OutputImagePixelType
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:721
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
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...
This filter is an implementation of a Canny edge detector for scalar-valued images.