ITK  4.5.0
Insight Segmentation and Registration Toolkit
itkGradientRecursiveGaussianImageFilter.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 __itkGradientRecursiveGaussianImageFilter_h
19 #define __itkGradientRecursiveGaussianImageFilter_h
20 
23 #include "itkImage.h"
24 #include "itkCovariantVector.h"
26 #include "itkProgressAccumulator.h"
27 #include "itkImageRegionIterator.h"
28 #include "itkVectorImage.h"
29 #include <vector>
30 
31 namespace itk
32 {
51 template< typename TInputImage,
52  typename TOutputImage = Image< CovariantVector<
53  typename NumericTraits< typename TInputImage::PixelType >::RealType,
54  TInputImage::ImageDimension >,
55  TInputImage::ImageDimension > >
57  public ImageToImageFilter< TInputImage, TOutputImage >
58 {
59 public:
65 
67  typedef TInputImage InputImageType;
68  typedef typename TInputImage::PixelType PixelType;
71 
77 
79  itkStaticConstMacro(ImageDimension, unsigned int,
80  TInputImage::ImageDimension);
81 
84 
88  typedef Image< InternalRealType,
89  itkGetStaticConstMacro(ImageDimension) > RealImageType;
90 
91 
96  typedef NthElementImageAdaptor< TOutputImage,
98 
100 
106 
112 
115 
118 
120  typedef typename TOutputImage::Pointer OutputImagePointer;
121 
123  typedef TOutputImage OutputImageType;
124  typedef typename OutputImageType::PixelType OutputPixelType;
128 
130  itkNewMacro(Self);
131 
135 
137  void SetSigma(ScalarRealType sigma);
138  RealType GetSigma() const;
140 
144  void SetNormalizeAcrossScale(bool normalizeInScaleSpace);
145  itkGetConstMacro(NormalizeAcrossScale, bool);
147 
153  virtual void GenerateInputRequestedRegion()
155 
166  itkSetMacro(UseImageDirection, bool);
167  itkGetConstMacro(UseImageDirection, bool);
168  itkBooleanMacro(UseImageDirection);
170 
171 #ifdef ITK_USE_CONCEPT_CHECKING
172  // Begin concept checking
173  itkConceptMacro( InputHasNumericTraitsCheck,
175  // End concept checking
176 #endif
177 
178 protected:
181  void PrintSelf(std::ostream & os, Indent indent) const;
182 
184  void GenerateData(void);
185 
186  // Override since the filter produces the entire dataset
188 
190 
191 private:
192 
193  template <typename TValueType>
195  {
196  // To transform Variable length vector we need to convert to and
197  // fro the CovariantVectorType
198  const CovariantVectorType gradient( it.Get().GetDataPointer() );
199  CovariantVectorType physicalGradient;
200  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient );
201  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), ImageDimension, false ) );
202  }
203 
204  template <typename T >
206  {
207  OutputPixelType correctedGradient;
208  const OutputPixelType & gradient = it.Get();
209 
210  const unsigned int nComponents = NumericTraits<OutputPixelType>::GetLength( gradient )/ImageDimension;
211 
212  for (unsigned int nc = 0; nc < nComponents; nc++ )
213  {
214  GradientVectorType componentGradient;
215  GradientVectorType correctedComponentGradient;
216  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
217  {
218  componentGradient[dim] = DefaultConvertPixelTraits<OutputPixelType>::GetNthComponent( nc*ImageDimension+dim, gradient );
219  }
220  it.GetImage()->TransformLocalVectorToPhysicalVector(componentGradient, correctedComponentGradient );
221  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
222  {
223  DefaultConvertPixelTraits<OutputPixelType>::SetNthComponent( nc*ImageDimension+dim, correctedGradient,
224  correctedComponentGradient[dim] );
225  }
226  it.Set(correctedGradient);
227  }
228  }
229 
230  template <template<typename, unsigned int> class P, class T, unsigned int N>
231  void TransformOutputPixel( ImageRegionIterator< Image< P<T,N>, N > > &it )
232  {
233  const OutputPixelType gradient = it.Get();
234  // This uses the more efficient set by reference method
235  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value() );
236  }
237 
238 
239  GradientRecursiveGaussianImageFilter(const Self &); //purposely not
240  // implemented
241  void operator=(const Self &); //purposely not
242 
243  // implemented
244 
245  std::vector< GaussianFilterPointer > m_SmoothingFilters;
248 
251 
254 };
255 } // end namespace itk
256 
257 #ifndef ITK_MANUAL_INSTANTIATION
258 #include "itkGradientRecursiveGaussianImageFilter.hxx"
259 #endif
260 
261 #endif
CovariantVector< OutputComponentType, ImageDimension > CovariantVectorType
RecursiveGaussianImageFilter< RealImageType, RealImageType > GaussianFilterType
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
RecursiveGaussianImageFilter< InputImageType, RealImageType > DerivativeFilterType
void Set(const PixelType &value) const
Base class for computing IIR convolution with an approximation of a Gaussian kernel.
Templated n-dimensional vector image class.
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
Image< InternalRealType, itkGetStaticConstMacro(ImageDimension) > RealImageType
Base class for all process objects that output image data.
CovariantVector< ScalarRealType, ImageDimension > GradientVectorType
static ComponentType GetNthComponent(int c, const PixelType &pixel)
NumericTraits< PixelType >::ScalarRealType ScalarRealType
NumericTraits< OutputPixelType >::ValueType OutputComponentType
void EnlargeOutputRequestedRegion(DataObject *output)
void SetNormalizeAcrossScale(bool normalizeInScaleSpace)
static unsigned int GetLength()
NumericTraits< InternalRealType >::ValueType InternalScalarRealType
void SetSigma(ScalarRealType sigma)
Presents an image as being composed of the N-th element of its pixels.
void TransformOutputPixel(ImageRegionIterator< Image< P< T, N >, N > > &it)
void PrintSelf(std::ostream &os, Indent indent) const
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
ImageToImageFilter< TInputImage, TOutputImage > Superclass
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
PixelType Get(void) const
void TransformOutputPixel(ImageRegionIterator< VectorImage< TValueType, ImageDimension > > &it)
A templated class holding a n-Dimensional covariant vector.
Base class for all data objects in ITK.
Templated n-dimensional image class.
Definition: itkImage.h:75
A multi-dimensional iterator templated over image type that walks a region of pixels.
NthElementImageAdaptor< TOutputImage, InternalScalarRealType > OutputImageAdaptorType
const ImageType * GetImage() const