ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkGradientImageFilter.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 itkGradientImageFilter_h
19 #define itkGradientImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkCovariantVector.h"
23 #include "itkImageRegionIterator.h"
24 
25 namespace itk
26 {
27 
28 
29 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
30 
31 
54 template< typename TInputImage,
55  typename TOperatorValueType = float,
56  typename TOutputValueType = float,
57  typename TOutputImageType = Image< CovariantVector< TOutputValueType,
58  TInputImage::ImageDimension >,
59  TInputImage::ImageDimension > >
60 class ITK_TEMPLATE_EXPORT GradientImageFilter:
61  public ImageToImageFilter< TInputImage, TOutputImageType >
62 {
63 public:
65  itkStaticConstMacro(InputImageDimension, unsigned int,
66  TInputImage::ImageDimension);
67  itkStaticConstMacro(OutputImageDimension, unsigned int,
68  TOutputImageType::ImageDimension);
70 
72  typedef TInputImage InputImageType;
73  typedef typename InputImageType::Pointer InputImagePointer;
74  typedef TOutputImageType OutputImageType;
75  typedef typename OutputImageType::Pointer OutputImagePointer;
76 
82 
84  itkNewMacro(Self);
85 
88 
90  typedef typename InputImageType::PixelType InputPixelType;
91  typedef TOperatorValueType OperatorValueType;
92  typedef TOutputValueType OutputValueType;
93  typedef typename OutputImageType::PixelType OutputPixelType;
94  typedef CovariantVector<
95  OutputValueType, itkGetStaticConstMacro(OutputImageDimension) >
97  typedef typename OutputImageType::RegionType OutputImageRegionType;
98 
105  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
106 
109  void SetUseImageSpacingOn()
110  { this->SetUseImageSpacing(true); }
111 
115  { this->SetUseImageSpacing(false); }
116 
119  itkSetMacro(UseImageSpacing, bool);
120  itkGetConstMacro(UseImageSpacing, bool);
121  itkBooleanMacro(UseImageSpacing);
122 
124  void OverrideBoundaryCondition(ImageBoundaryCondition< TInputImage >* boundaryCondition);
125 
126 #ifdef ITK_USE_CONCEPT_CHECKING
127  // Begin concept checking
128  itkConceptMacro( InputConvertibleToOutputCheck,
130  itkConceptMacro( OutputHasNumericTraitsCheck,
132  // End concept checking
133 #endif
134 
145  itkSetMacro(UseImageDirection, bool);
146  itkGetConstMacro(UseImageDirection, bool);
147  itkBooleanMacro(UseImageDirection);
149 
150 protected:
152  virtual ~GradientImageFilter() ITK_OVERRIDE;
153  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
154 
165  void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
166  ThreadIdType threadId) ITK_OVERRIDE;
167 
168 private:
169  ITK_DISALLOW_COPY_AND_ASSIGN(GradientImageFilter);
170 
171  virtual void GenerateOutputInformation() ITK_OVERRIDE;
172 
173  // An overloaded method which may transform the gradient to a
174  // physical vector and converts to the correct output pixel type.
175  template <typename TValue>
176  void SetOutputPixel( ImageRegionIterator< VectorImage<TValue,OutputImageDimension> > &it, CovariantVectorType &gradient )
177  {
178  if ( this->m_UseImageDirection )
179  {
180  CovariantVectorType physicalGradient;
181  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient );
182  it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) );
183  }
184  else
185  {
186  it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) );
187  }
188  }
189 
190  template <typename T >
192  {
193  // This uses the more efficient set by reference method
194  if ( this->m_UseImageDirection )
195  {
196  it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, it.Value() );
197  }
198  else
199  {
200  it.Value() = gradient;
201  }
202  }
203 
204 
206 
207  // flag to take or not the image direction into account
208  // when computing the derivatives.
210 
211  // allow setting the the m_BoundaryCondition
213 };
214 } // end namespace itk
215 
216 #ifndef ITK_MANUAL_INSTANTIATION
217 #include "itkGradientImageFilter.hxx"
218 #endif
219 
220 #endif
ImageBoundaryCondition< TInputImage, TInputImage > * m_BoundaryCondition
Light weight base class for most itk classes.
InputImageType::Pointer InputImagePointer
TOperatorValueType OperatorValueType
InputImageType::PixelType InputPixelType
Templated n-dimensional vector image class.
OutputImageType::RegionType OutputImageRegionType
OutputImageType::Pointer OutputImagePointer
SmartPointer< const Self > ConstPointer
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
CovariantVector< OutputValueType, itkGetStaticConstMacro(OutputImageDimension) > CovariantVectorType
SmartPointer< Self > Pointer
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
OutputImageType::PixelType OutputPixelType
ImageToImageFilter< InputImageType, OutputImageType > Superclass
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
ValueType * GetDataPointer()
#define itkConceptMacro(name, concept)
A templated class holding a n-Dimensional covariant vector.
A multi-dimensional iterator templated over image type that walks a region of pixels.
const ImageType * GetImage() const
Computes the gradient of an image using directional derivatives.