ITK  5.0.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 "itkMultiThreaderBase.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:
91  ITK_DISALLOW_COPY_AND_ASSIGN(CannyEdgeDetectionImageFilter);
92 
96 
98  using InputImageType = TInputImage;
99  using OutputImageType = TOutputImage;
100 
104 
106  using InputImagePixelType = typename TInputImage::PixelType;
107  using OutputImagePixelType = typename TOutputImage::PixelType;
110 
114 
120 
125 
127  itkNewMacro(Self);
128 
132 
135 
137  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
138  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
139 
142 
144  itkSetMacro(Variance, ArrayType);
145  itkGetConstMacro(Variance, const ArrayType);
147 
150  itkSetMacro(MaximumError, ArrayType);
151  itkGetConstMacro(MaximumError, const ArrayType);
153 
155  void SetVariance(const typename ArrayType::ValueType v)
156  {
157  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
158  {
159  if ( Math::NotExactlyEquals(m_Variance[i], v) )
160  {
161  m_Variance.Fill(v);
162  this->Modified();
163  break;
164  }
165  }
166  }
168 
171  void SetMaximumError(const typename ArrayType::ValueType v)
172  {
173  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
174  {
175  if ( Math::NotExactlyEquals(m_MaximumError[i], v) )
176  {
177  m_MaximumError.Fill(v);
178  this->Modified();
179  break;
180  }
181  }
182  }
184 
195  itkSetMacro(UpperThreshold, OutputImagePixelType);
196  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
197 
198  itkSetMacro(LowerThreshold, OutputImagePixelType);
199  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
200 
202  {
203  return this->m_MultiplyImageFilter->GetOutput();
204  }
205 
206 #ifdef ITK_USE_CONCEPT_CHECKING
207  // Begin concept checking
208  itkConceptMacro( InputHasNumericTraitsCheck,
210  itkConceptMacro( OutputHasNumericTraitsCheck,
212  itkConceptMacro( SameDimensionCheck,
214  itkConceptMacro( InputIsFloatingPointCheck,
216  itkConceptMacro( OutputIsFloatingPointCheck,
218  // End concept checking
219 #endif
220 
221 protected:
223  void PrintSelf(std::ostream & os, Indent indent) const override;
224 
225  void GenerateData() override;
226 
227  using GaussianImageFilterType =
231 
232 private:
233  ~CannyEdgeDetectionImageFilter() override = default;
234 
236  void AllocateUpdateBuffer();
237 
239  void HysteresisThresholding();
240 
242  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
243 
246  void ThreadedCompute2ndDerivative(const OutputImageRegionType& outputRegionForThread);
247 
248 
252  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
253  void *globalData);
254 
257  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType& outputRegionForThread);
258 
261 
262  OutputImagePixelType m_UpperThreshold; //should be float here?
263  OutputImagePixelType m_LowerThreshold; //should be float here?
264 
265  typename OutputImageType::Pointer m_UpdateBuffer1;
266 
269 
273 
280 
281  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
282 
283  SizeValueType m_Stride[ImageDimension];
285 
288 
290 };
291 } //end of namespace itk
292 
293 #ifndef ITK_MANUAL_INSTANTIATION
294 #include "itkCannyEdgeDetectionImageFilter.hxx"
295 #endif
296 
297 #endif
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.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
A NeighborhoodOperator for taking an n-th order derivative at a pixel.
DerivativeOperator< OutputImagePixelType, Self::ImageDimension > m_ComputeCannyEdge2ndDerivativeOper
void SetVariance(const typename ArrayType::ValueType v)
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
GaussianImageFilterType::Pointer m_GaussianFilter
typename OutputImageType::PixelType OutputImagePixelType
typename InputImageType::PixelType InputImagePixelType
MultiplyImageFilterType::Pointer m_MultiplyImageFilter
DerivativeOperator< OutputImagePixelType, Self::ImageDimension > m_ComputeCannyEdge1stDerivativeOper
typename OutputImageType::RegionType OutputImageRegionType
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
typename InputImageType::RegionType InputImageRegionType
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.