ITK  4.3.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 
173  itkConceptMacro( InputHasNumericTraitsCheck,
175 
177 #endif
178 
179 protected:
182  void PrintSelf(std::ostream & os, Indent indent) const;
183 
185  void GenerateData(void);
186 
187  // Override since the filter produces the entire dataset
188  void EnlargeOutputRequestedRegion(DataObject *output);
189 
190  void GenerateOutputInformation();
191 
192 private:
193 
194  template <class TValueType>
196  {
197  // To transform Variable length vector we need to convert to and
198  // fro the CovariantVectorType
199  const CovariantVectorType gradient( it.Get().GetDataPointer() );
200  CovariantVectorType physicalGradient;
201  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient );
202  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), ImageDimension, false ) );
203  }
204 
205  template <class T >
206  void TransformOutputPixel( ImageRegionIterator< T > &it )
207  {
208  OutputPixelType correctedGradient;
209  const OutputPixelType & gradient = it.Get();
210 
211  const unsigned int nComponents = NumericTraits<OutputPixelType>::GetLength( gradient )/ImageDimension;
212 
213  for (unsigned int nc = 0; nc < nComponents; nc++ )
214  {
215  GradientVectorType componentGradient;
216  GradientVectorType correctedComponentGradient;
217  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
218  {
219  componentGradient[dim] = DefaultConvertPixelTraits<OutputPixelType>::GetNthComponent( nc*ImageDimension+dim, gradient );
220  }
221  it.GetImage()->TransformLocalVectorToPhysicalVector(componentGradient, correctedComponentGradient );
222  for (unsigned int dim = 0; dim < ImageDimension; dim++ )
223  {
224  DefaultConvertPixelTraits<OutputPixelType>::SetNthComponent( nc*ImageDimension+dim, correctedGradient,
225  correctedComponentGradient[dim] );
226  }
227  it.Set(correctedGradient);
228  }
229  }
230 
231  template <template<class, unsigned int> class P, class T, unsigned int N>
232  void TransformOutputPixel( ImageRegionIterator< Image< P<T,N>, N > > &it )
233  {
234  const OutputPixelType gradient = it.Get();
235  // This uses the more efficient set by reference method
236  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value() );
237  }
238 
239 
240  GradientRecursiveGaussianImageFilter(const Self &); //purposely not
241  // implemented
242  void operator=(const Self &); //purposely not
243 
244  // implemented
245 
246  std::vector< GaussianFilterPointer > m_SmoothingFilters;
249 
252 
255 };
256 } // end namespace itk
257 
258 #ifndef ITK_MANUAL_INSTANTIATION
259 #include "itkGradientRecursiveGaussianImageFilter.hxx"
260 #endif
261 
262 #endif
263