ITK  4.13.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;
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);
149 
152  itkSetMacro(MaximumError, ArrayType);
153  itkGetConstMacro(MaximumError, const ArrayType);
155 
157  void SetVariance(const typename ArrayType::ValueType v)
158  {
159  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
160  {
161  if ( Math::NotExactlyEquals(m_Variance[i], v) )
162  {
163  m_Variance.Fill(v);
164  this->Modified();
165  break;
166  }
167  }
168  }
170 
173  void SetMaximumError(const typename ArrayType::ValueType v)
174  {
175  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
176  {
177  if ( Math::NotExactlyEquals(m_MaximumError[i], v) )
178  {
179  m_MaximumError.Fill(v);
180  this->Modified();
181  break;
182  }
183  }
184  }
186 
197  itkSetMacro(UpperThreshold, OutputImagePixelType);
198  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
199 
200  itkSetMacro(LowerThreshold, OutputImagePixelType);
201  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
202 
204  {
205  return this->m_MultiplyImageFilter->GetOutput();
206  }
207 
215  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
216 
217 #ifdef ITK_USE_CONCEPT_CHECKING
218  // Begin concept checking
219  itkConceptMacro( InputHasNumericTraitsCheck,
221  itkConceptMacro( OutputHasNumericTraitsCheck,
223  itkConceptMacro( SameDimensionCheck,
225  itkConceptMacro( InputIsFloatingPointCheck,
227  itkConceptMacro( OutputIsFloatingPointCheck,
229  // End concept checking
230 #endif
231 
232 protected:
234  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
235 
236  void GenerateData() ITK_OVERRIDE;
237 
238  typedef DiscreteGaussianImageFilter< InputImageType, OutputImageType >
241  OutputImageType, OutputImageType > MultiplyImageFilterType;
242 
243 private:
244  ITK_DISALLOW_COPY_AND_ASSIGN(CannyEdgeDetectionImageFilter);
245 
246  virtual ~CannyEdgeDetectionImageFilter() ITK_OVERRIDE {}
247 
250  {
252  };
253 
255  void AllocateUpdateBuffer();
256 
258  void HysteresisThresholding();
259 
261  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
262 
266  void Compute2ndDerivative();
267 
276  // virtual
277  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
278 
284  void ThreadedCompute2ndDerivative(const OutputImageRegionType &
285  outputRegionForThread, ThreadIdType threadId);
286 
291  Compute2ndDerivativeThreaderCallback(void *arg);
292 
296  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
297  void *globalData);
298 
303  void Compute2ndDerivativePos();
304 
310  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &
311  outputRegionForThread, ThreadIdType threadId);
312 
317  Compute2ndDerivativePosThreaderCallback(void *arg);
318 
320 
322 
323  OutputImagePixelType m_UpperThreshold; //should be float here?
324 
325  OutputImagePixelType m_LowerThreshold; //should be float here?
326 
327  typename OutputImageType::Pointer m_UpdateBuffer1;
328 
331 
335 
343 
344  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
345 
346  SizeValueType m_Stride[ImageDimension];
348 
351 
353 };
354 } //end of namespace itk
355 
356 #ifndef ITK_MANUAL_INSTANTIATION
357 #include "itkCannyEdgeDetectionImageFilter.hxx"
358 #endif
359 
360 #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.