ITK  5.0.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<
54  TInputImage::ImageDimension >,
55  TInputImage::ImageDimension > >
56 class ITK_TEMPLATE_EXPORT GradientRecursiveGaussianImageFilter:
57  public ImageToImageFilter< TInputImage, TOutputImage >
58 {
59 public:
60  ITK_DISALLOW_COPY_AND_ASSIGN(GradientRecursiveGaussianImageFilter);
61 
67 
69  using InputImageType = TInputImage;
70  using PixelType = typename TInputImage::PixelType;
73 
79 
81  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
82 
85 
90  Self::ImageDimension >;
91 
92 
97  using OutputImageAdaptorType = NthElementImageAdaptor< TOutputImage,
99 
101 
104  Self::ImageDimension >;
105 
109 
113 
116 
119 
121  using OutputImagePointer = typename TOutputImage::Pointer;
122 
124  using OutputImageType = TOutputImage;
125  using OutputPixelType = typename OutputImageType::PixelType;
127  using CovariantVectorType =
129 
131  itkNewMacro(Self);
132 
136 
138  void SetSigmaArray(const SigmaArrayType & sigmas);
139  void SetSigma(ScalarRealType sigma);
141 
142  SigmaArrayType GetSigmaArray() const;
143  ScalarRealType GetSigma() const;
144 
148  void SetNormalizeAcrossScale(bool normalizeInScaleSpace);
149  itkGetConstMacro(NormalizeAcrossScale, bool);
151 
157  void GenerateInputRequestedRegion() override;
158 
169  itkSetMacro(UseImageDirection, bool);
170  itkGetConstMacro(UseImageDirection, bool);
171  itkBooleanMacro(UseImageDirection);
173 
174 #ifdef ITK_USE_CONCEPT_CHECKING
175  // Begin concept checking
176  // Does not seem to work with wrappings, disabled
177  // itkConceptMacro( InputHasNumericTraitsCheck,
178  // ( Concept::HasNumericTraits< PixelType > ) );
179  // End concept checking
180 #endif
181 
182 protected:
184  ~GradientRecursiveGaussianImageFilter() override = default;
185  void PrintSelf(std::ostream & os, Indent indent) const override;
186 
188  void GenerateData() override;
189 
190  // Override since the filter produces the entire dataset
191  void EnlargeOutputRequestedRegion(DataObject *output) override;
192 
193  void GenerateOutputInformation() override;
194 
195 private:
196 
197  template <typename TValue>
199  {
200  // To transform Variable length vector we need to convert to and
201  // fro the CovariantVectorType
202  const CovariantVectorType gradient( it.Get().GetDataPointer() );
203  CovariantVectorType physicalGradient;
204  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient );
205  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), ImageDimension, false ) );
206  }
207 
208  template <typename T >
210  {
211  OutputPixelType correctedGradient;
212  const OutputPixelType & gradient = it.Get();
213 
214  const unsigned int nComponents = NumericTraits<OutputPixelType>::GetLength( gradient )/ImageDimension;
215 
216  for (unsigned int nc = 0; nc < nComponents; nc++ )
217  {
218  GradientVectorType componentGradient;
219  GradientVectorType correctedComponentGradient;
220  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
221  {
222  componentGradient[dim] = DefaultConvertPixelTraits<OutputPixelType>::GetNthComponent( nc*ImageDimension+dim, gradient );
223  }
224  it.GetImage()->TransformLocalVectorToPhysicalVector(componentGradient, correctedComponentGradient );
225  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
226  {
227  DefaultConvertPixelTraits<OutputPixelType>::SetNthComponent( nc*ImageDimension+dim, correctedGradient,
228  correctedComponentGradient[dim] );
229  }
230  }
231  it.Set(correctedGradient);
232  }
233 
234  template <template<typename, unsigned int> class P, class T, unsigned int N>
235  void TransformOutputPixel( ImageRegionIterator< Image< P<T,N>, N > > &it )
236  {
237  const OutputPixelType gradient = it.Get();
238  // This uses the more efficient set by reference method
239  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value() );
240  }
241 
242 
243  std::vector< GaussianFilterPointer > m_SmoothingFilters;
246 
249 
252 
255 };
256 } // end namespace itk
257 
258 #ifndef ITK_MANUAL_INSTANTIATION
259 #include "itkGradientRecursiveGaussianImageFilter.hxx"
260 #endif
261 
262 #endif
typename NumericTraits< PixelType >::ScalarRealType ScalarRealType
typename OutputImageType::Pointer OutputImagePointer
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
Define numeric traits for std::vector.
void Set(const PixelType &value) const
typename NumericTraits< RealType >::FloatType InternalRealType
typename NumericTraits< InternalRealType >::ValueType InternalScalarRealType
Base class for computing IIR convolution with an approximation of a Gaussian kernel.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Templated n-dimensional vector image class.
typename OutputImageAdaptorType::Pointer OutputImageAdaptorPointer
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
Base class for all process objects that output image data.
static ComponentType GetNthComponent(int c, const PixelType &pixel)
void TransformOutputPixel(ImageRegionIterator< VectorImage< TValue, ImageDimension > > &it)
TOutputImage OutputImageType
typename DerivativeFilterType::Pointer DerivativeFilterPointer
Presents an image as being composed of the N-th element of its pixels.
typename NumericTraits< OutputPixelType >::ValueType OutputComponentType
void TransformOutputPixel(ImageRegionIterator< Image< P< T, N >, N > > &it)
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
typename NumericTraits< PixelType >::RealType RealType
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.
const ImageType * GetImage() const