ITK  5.2.0
Insight Toolkit
itkCannyEdgeDetectionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 
87 template <typename TInputImage, typename TOutputImage>
88 class ITK_TEMPLATE_EXPORT CannyEdgeDetectionImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
89 {
90 public:
91  ITK_DISALLOW_COPY_AND_MOVE(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 
119 
124 
126  itkNewMacro(Self);
127 
131 
134 
136  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
137  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
138 
141 
143  itkSetMacro(Variance, ArrayType);
144  itkGetConstMacro(Variance, const ArrayType);
146 
149  itkSetMacro(MaximumError, ArrayType);
150  itkGetConstMacro(MaximumError, const ArrayType);
152 
154  void
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
173  {
174  for (unsigned int i = 0; i < TInputImage::ImageDimension; i++)
175  {
176  if (Math::NotExactlyEquals(m_MaximumError[i], v))
177  {
178  m_MaximumError.Fill(v);
179  this->Modified();
180  break;
181  }
182  }
183  }
185 
196  itkSetMacro(UpperThreshold, OutputImagePixelType);
197  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
198 
199  itkSetMacro(LowerThreshold, OutputImagePixelType);
200  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
201 
202  OutputImageType *
204  {
205  return this->m_MultiplyImageFilter->GetOutput();
206  }
207 
208 #ifdef ITK_USE_CONCEPT_CHECKING
209  // Begin concept checking
215  // End concept checking
216 #endif
217 
218 protected:
220  void
221  PrintSelf(std::ostream & os, Indent indent) const override;
222 
223  void
224  GenerateData() override;
225 
228 
229 private:
230  ~CannyEdgeDetectionImageFilter() override = default;
231 
233  void
234  AllocateUpdateBuffer();
235 
237  void
238  HysteresisThresholding();
239 
241  void
242  FollowEdge(IndexType index, const OutputImageType * multiplyImageFilterOutput);
243 
246  void
247  ThreadedCompute2ndDerivative(const OutputImageRegionType & outputRegionForThread);
248 
249 
254  ComputeCannyEdge(const NeighborhoodType & it, void * globalData);
255 
258  void
259  ThreadedCompute2ndDerivativePos(const OutputImageRegionType & outputRegionForThread);
260 
263 
264  OutputImagePixelType m_UpperThreshold; // should be float here?
265  OutputImagePixelType m_LowerThreshold; // should be float here?
266 
267  typename OutputImageType::Pointer m_UpdateBuffer1;
268 
271 
275 
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
itk::CannyEdgeDetectionImageFilter::m_Variance
ArrayType m_Variance
Definition: itkCannyEdgeDetectionImageFilter.h:261
itk::DiscreteGaussianImageFilter
Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian...
Definition: itkDiscreteGaussianImageFilter.h:63
itkConstNeighborhoodIterator.h
itk::ListNode::Previous
ListNode * Previous
Definition: itkCannyEdgeDetectionImageFilter.h:39
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itkObjectStore.h
itk::CannyEdgeDetectionImageFilter::m_MultiplyImageFilter
MultiplyImageFilterType::Pointer m_MultiplyImageFilter
Definition: itkCannyEdgeDetectionImageFilter.h:274
itk::CannyEdgeDetectionImageFilter::GetNonMaximumSuppressionImage
OutputImageType * GetNonMaximumSuppressionImage()
Definition: itkCannyEdgeDetectionImageFilter.h:203
itk::CannyEdgeDetectionImageFilter::m_UpperThreshold
OutputImagePixelType m_UpperThreshold
Definition: itkCannyEdgeDetectionImageFilter.h:264
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::CannyEdgeDetectionImageFilter::m_UpdateBuffer1
OutputImageType::Pointer m_UpdateBuffer1
Definition: itkCannyEdgeDetectionImageFilter.h:267
itk::CannyEdgeDetectionImageFilter< ImageType, ImageType >::IndexType
typename ImageType ::IndexType IndexType
Definition: itkCannyEdgeDetectionImageFilter.h:108
itk::ListNode::m_Value
TValue m_Value
Definition: itkCannyEdgeDetectionImageFilter.h:36
itk::Concept::SameDimension
Definition: itkConceptChecking.h:694
itk::SparseFieldLayer
A very simple linked list that is used to manage nodes in a layer of a sparse field level-set solver.
Definition: itkSparseFieldLayer.h:172
itk::ImageToImageFilter< ImageType, ImageType >::InputImagePixelType
typename InputImageType::PixelType InputImagePixelType
Definition: itkImageToImageFilter.h:133
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ObjectStore
A specialized memory management object for allocating and destroying contiguous blocks of objects.
Definition: itkObjectStore.h:84
itk::CannyEdgeDetectionImageFilter::m_NodeList
ListPointerType m_NodeList
Definition: itkCannyEdgeDetectionImageFilter.h:287
itk::CannyEdgeDetectionImageFilter::SetMaximumError
void SetMaximumError(const typename ArrayType::ValueType v)
Definition: itkCannyEdgeDetectionImageFilter.h:172
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::CannyEdgeDetectionImageFilter::m_Center
SizeValueType m_Center
Definition: itkCannyEdgeDetectionImageFilter.h:284
itk::CannyEdgeDetectionImageFilter< ImageType, ImageType >::SizeValueType
typename ImageType ::SizeValueType SizeValueType
Definition: itkCannyEdgeDetectionImageFilter.h:109
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:946
itk::CannyEdgeDetectionImageFilter< ImageType, ImageType >::ListPointerType
typename ListType::Pointer ListPointerType
Definition: itkCannyEdgeDetectionImageFilter.h:123
itk::CannyEdgeDetectionImageFilter
This filter is an implementation of a Canny edge detector for scalar-valued images.
Definition: itkCannyEdgeDetectionImageFilter.h:88
itkMultiplyImageFilter.h
itk::ImageToImageFilter< ImageType, ImageType >::InputImageType
ImageType InputImageType
Definition: itkImageToImageFilter.h:129
itk::FixedArray< double, Self::ImageDimension >
itk::CannyEdgeDetectionImageFilter::m_NodeStore
ListNodeStorageType::Pointer m_NodeStore
Definition: itkCannyEdgeDetectionImageFilter.h:286
itk::ImageSource< ImageType >::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::CannyEdgeDetectionImageFilter::m_MaximumError
ArrayType m_MaximumError
Definition: itkCannyEdgeDetectionImageFilter.h:262
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::DerivativeOperator< OutputImagePixelType, Self::ImageDimension >
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itkMultiThreaderBase.h
itk::CannyEdgeDetectionImageFilter::m_ComputeCannyEdge1stDerivativeOper
DerivativeOperator< OutputImagePixelType, Self::ImageDimension > m_ComputeCannyEdge1stDerivativeOper
Definition: itkCannyEdgeDetectionImageFilter.h:278
itk::ImageSource< ImageType >::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itk::CannyEdgeDetectionImageFilter::m_GaussianFilter
GaussianImageFilterType::Pointer m_GaussianFilter
Definition: itkCannyEdgeDetectionImageFilter.h:270
itk::CannyEdgeDetectionImageFilter::SetVariance
void SetVariance(const typename ArrayType::ValueType v)
Definition: itkCannyEdgeDetectionImageFilter.h:155
itk::ListNode::Next
ListNode * Next
Definition: itkCannyEdgeDetectionImageFilter.h:38
itk::ZeroFluxNeumannBoundaryCondition
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
Definition: itkZeroFluxNeumannBoundaryCondition.h:58
itkDerivativeOperator.h
itk::ListNode
Definition: itkCannyEdgeDetectionImageFilter.h:33
itk::CannyEdgeDetectionImageFilter::m_LowerThreshold
OutputImagePixelType m_LowerThreshold
Definition: itkCannyEdgeDetectionImageFilter.h:265
itk::MultiplyImageFilter
Pixel-wise multiplication of two images.
Definition: itkMultiplyImageFilter.h:43
itk::ImageToImageFilter< ImageType, ImageType >::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itkDiscreteGaussianImageFilter.h
itkMath.h
itk::CannyEdgeDetectionImageFilter::m_ComputeCannyEdge2ndDerivativeOper
DerivativeOperator< OutputImagePixelType, Self::ImageDimension > m_ComputeCannyEdge2ndDerivativeOper
Definition: itkCannyEdgeDetectionImageFilter.h:279
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::FixedArray< double, Self::ImageDimension >::ValueType
double ValueType
Definition: itkFixedArray.h:62
itk::ImageSource< ImageType >::OutputImageType
ImageType OutputImageType
Definition: itkImageSource.h:90
itkSparseFieldLayer.h
itk::CannyEdgeDetectionImageFilter::m_OutputImage
OutputImageType * m_OutputImage
Definition: itkCannyEdgeDetectionImageFilter.h:289