ITK  6.0.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  * https://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 
133  itkOverrideGetNameOfClassMacro(CannyEdgeDetectionImageFilter);
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);
149  itkSetMacro(MaximumError, ArrayType);
150  itkGetConstMacro(MaximumError, const ArrayType);
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  }
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  }
188  itkSetMacro(UpperThreshold, OutputImagePixelType);
189  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
190 
193  itkSetMacro(LowerThreshold, OutputImagePixelType);
194  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
195 
196  OutputImageType *
198  {
199  return this->m_MultiplyImageFilter->GetOutput();
200  }
201 
202 #ifdef ITK_USE_CONCEPT_CHECKING
203  // Begin concept checking
209  // End concept checking
210 #endif
211 
212 protected:
214  void
215  PrintSelf(std::ostream & os, Indent indent) const override;
216 
217  void
218  GenerateData() override;
219 
222 
223 private:
224  ~CannyEdgeDetectionImageFilter() override = default;
225 
227  void
228  AllocateUpdateBuffer();
229 
231  void
232  HysteresisThresholding();
233 
235  void
236  FollowEdge(IndexType index, const OutputImageType * multiplyImageFilterOutput);
237 
240  void
241  ThreadedCompute2ndDerivative(const OutputImageRegionType & outputRegionForThread);
242 
243 
248  ComputeCannyEdge(const NeighborhoodType & it, void * globalData);
249 
252  void
253  ThreadedCompute2ndDerivativePos(const OutputImageRegionType & outputRegionForThread);
254 
255  ArrayType m_Variance{};
256  ArrayType m_MaximumError{};
257 
258  OutputImagePixelType m_UpperThreshold{}; // should be float here?
259  OutputImagePixelType m_LowerThreshold{}; // should be float here?
260 
261  typename OutputImageType::Pointer m_UpdateBuffer1{};
262 
264  typename GaussianImageFilterType::Pointer m_GaussianFilter{};
265 
268  typename MultiplyImageFilterType::Pointer m_MultiplyImageFilter{};
269 
274 
275  std::slice m_ComputeCannyEdgeSlice[ImageDimension]{};
276 
277  SizeValueType m_Stride[ImageDimension]{};
278  SizeValueType m_Center{};
279 
280  typename ListNodeStorageType::Pointer m_NodeStore{};
281  ListPointerType m_NodeList{};
282 
283  OutputImageType * m_OutputImage{};
284 };
285 } // end of namespace itk
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 # include "itkCannyEdgeDetectionImageFilter.hxx"
289 #endif
290 
291 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::DiscreteGaussianImageFilter
Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian...
Definition: itkDiscreteGaussianImageFilter.h:64
itkConstNeighborhoodIterator.h
itk::ListNode::Previous
ListNode * Previous
Definition: itkCannyEdgeDetectionImageFilter.h:39
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:716
itkObjectStore.h
itk::CannyEdgeDetectionImageFilter::GetNonMaximumSuppressionImage
OutputImageType * GetNonMaximumSuppressionImage()
Definition: itkCannyEdgeDetectionImageFilter.h:197
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< 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:696
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:162
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:55
itk::ObjectStore
A specialized memory management object for allocating and destroying contiguous blocks of objects.
Definition: itkObjectStore.h:84
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< ImageType, ImageType >::SizeValueType
typename ImageType ::SizeValueType SizeValueType
Definition: itkCannyEdgeDetectionImageFilter.h:109
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:948
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::ImageSource< ImageType >::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
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::ImageSource< ImageType >::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
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::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::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::FixedArray< double, Self::ImageDimension >::ValueType
double ValueType
Definition: itkFixedArray.h:63
itk::ImageSource< ImageType >::OutputImageType
ImageType OutputImageType
Definition: itkImageSource.h:90
itkSparseFieldLayer.h