ITK  4.3.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 
114  typedef ConstNeighborhoodIterator< OutputImageType,
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 
228 protected:
230  void PrintSelf(std::ostream & os, Indent indent) const;
231 
232  void GenerateData();
233 
236  typedef MultiplyImageFilter< OutputImageType,
237  OutputImageType, OutputImageType > MultiplyImageFilterType;
238 
239 private:
240  CannyEdgeDetectionImageFilter(const Self &); //purposely not implemented
241  void operator=(const Self &); //purposely not implemented
242 
244 
247  {
249  };
250 
252  void AllocateUpdateBuffer();
253 
255  void HysteresisThresholding();
256 
258  void FollowEdge(IndexType index, const OutputImageType *multiplyImageFilterOutput);
259 
263  void Compute2ndDerivative();
264 
273  // virtual
274  // int SplitUpdateContainer(int i, int num, ThreadRegionType& splitRegion);
275 
281  void ThreadedCompute2ndDerivative(const OutputImageRegionType &
282  outputRegionForThread, ThreadIdType threadId);
283 
288  Compute2ndDerivativeThreaderCallback(void *arg);
289 
293  OutputImagePixelType ComputeCannyEdge(const NeighborhoodType & it,
294  void *globalData);
295 
300  void Compute2ndDerivativePos();
301 
307  void ThreadedCompute2ndDerivativePos(const OutputImageRegionType &
308  outputRegionForThread, ThreadIdType threadId);
309 
314  Compute2ndDerivativePosThreaderCallback(void *arg);
315 
318 
322 
324  OutputImagePixelType m_UpperThreshold; //should be float here?
325 
327  OutputImagePixelType m_LowerThreshold; //should be float here?
328 
330  typename OutputImageType::Pointer m_UpdateBuffer1;
331 
334 
338 
346 
347  std::slice m_ComputeCannyEdgeSlice[ImageDimension];
348 
349  SizeValueType m_Stride[ImageDimension];
351 
354 
355  const InputImageType *m_InputImage;
356  OutputImageType *m_OutputImage;
357 };
358 } //end of namespace itk
359 
360 #ifndef ITK_MANUAL_INSTANTIATION
361 #include "itkCannyEdgeDetectionImageFilter.hxx"
362 #endif
363 
364 #endif
365