ITK  4.2.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 
29 namespace itk
30 {
31 template< class TValueType >
32 class ListNode
33 {
34 public:
35  TValueType m_Value;
36 
39 };
40 
83 template< class TInputImage, class TOutputImage >
85  public ImageToImageFilter< TInputImage, TOutputImage >
86 {
87 public:
91 
93  typedef TInputImage InputImageType;
94  typedef TOutputImage OutputImageType;
95 
99 
101  typedef typename TInputImage::PixelType InputImagePixelType;
102  typedef typename TOutputImage::PixelType OutputImagePixelType;
103  typedef typename TInputImage::IndexType IndexType;
105 
110 
116 
121 
123  itkNewMacro(Self);
124 
126  typedef typename TOutputImage::RegionType OutputImageRegionType;
127  typedef typename TInputImage::RegionType InputImageRegionType;
128 
131 
133  itkStaticConstMacro(ImageDimension, unsigned int,
134  TInputImage::ImageDimension);
135  itkStaticConstMacro(OutputImageDimension, unsigned int,
136  TOutputImage::ImageDimension);
138 
141 
143  itkSetMacro(Variance, ArrayType);
144  itkGetConstMacro(Variance, const ArrayType);
145  itkSetMacro(MaximumError, ArrayType);
146  itkGetConstMacro(MaximumError, const ArrayType);
148 
151  void SetVariance(const typename ArrayType::ValueType v)
152  {
153  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
154  {
155  if ( m_Variance[i] != v )
156  {
157  m_Variance.Fill(v);
158  this->Modified();
159  break;
160  }
161  }
162  }
164 
167  void SetMaximumError(const typename ArrayType::ValueType v)
168  {
169  for ( unsigned int i = 0; i < TInputImage::ImageDimension; i++ )
170  {
171  if ( m_MaximumError[i] != v )
172  {
173  m_MaximumError.Fill(v);
174  this->Modified();
175  break;
176  }
177  }
178  }
180 
190 
191  itkSetMacro(UpperThreshold, OutputImagePixelType);
192  itkGetConstMacro(UpperThreshold, OutputImagePixelType);
193 
194  itkSetMacro(LowerThreshold, OutputImagePixelType);
195  itkGetConstMacro(LowerThreshold, OutputImagePixelType);
196 
197  OutputImageType * GetNonMaximumSuppressionImage()
198  {
199  return this->m_MultiplyImageFilter->GetOutput();
200  }
201 
209  virtual void GenerateInputRequestedRegion()
211 
212 #ifdef ITK_USE_CONCEPT_CHECKING
213 
214  itkConceptMacro( InputHasNumericTraitsCheck,
216  itkConceptMacro( OutputHasNumericTraitsCheck,
218  itkConceptMacro( SameDimensionCheck,
220  itkConceptMacro( InputIsFloatingPointCheck,
222  itkConceptMacro( OutputIsFloatingPointCheck,
224 
226 #endif
227 protected:
229  void PrintSelf(std::ostream & os, Indent indent) const;
231 
232  void GenerateData();
233 
238 private:
239  CannyEdgeDetectionImageFilter(const Self &); //purposely not implemented
240  void operator=(const Self &); //purposely not implemented
241 
243 
246  {
248  };
249 
251  void AllocateUpdateBuffer();
252 
254  void HysteresisThresholding();
255 
257  void FollowEdge(IndexType index);
258 
262  void Compute2ndDerivative();
263 
272  // virtual
273  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
274 
280  void ThreadedCompute2ndDerivative(const OutputImageRegionType &
281  outputRegionForThread, ThreadIdType threadId);
282 
287  Compute2ndDerivativeThreaderCallback(void *arg);
288 
292  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
293  void *globalData);
294 
299  void Compute2ndDerivativePos();
300 
306  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &
307  outputRegionForThread, ThreadIdType threadId);
308 
313  Compute2ndDerivativePosThreaderCallback(void *arg);
314 
317 
321 
323  OutputImagePixelType m_UpperThreshold; //should be float here?
324 
326  OutputImagePixelType m_LowerThreshold; //should be float here?
327 
329  typename OutputImageType::Pointer m_UpdateBuffer1;
330 
333 
337 
345 
346  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
347 
348  SizeValueType m_Stride[ImageDimension];
350 
353 };
354 } //end of namespace itk
355 
356 #ifndef ITK_MANUAL_INSTANTIATION
357 #include "itkCannyEdgeDetectionImageFilter.hxx"
358 #endif
359 
360 #endif
361