ITK  5.2.0
Insight Toolkit
itkGradientImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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>
30 class VectorImage;
31 
32 
61 template <typename TInputImage,
62  typename TOperatorValueType = float,
63  typename TOutputValueType = float,
64  typename TOutputImageType =
65  Image<CovariantVector<TOutputValueType, TInputImage::ImageDimension>, TInputImage::ImageDimension>>
66 class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInputImage, TOutputImageType>
67 {
68 public:
69  ITK_DISALLOW_COPY_AND_ASSIGN(GradientImageFilter);
71 
73  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
74  static constexpr unsigned int OutputImageDimension = TOutputImageType::ImageDimension;
75 
77  using InputImageType = TInputImage;
78  using InputImagePointer = typename InputImageType::Pointer;
79  using OutputImageType = TOutputImageType;
80  using OutputImagePointer = typename OutputImageType::Pointer;
81 
87 
89  itkNewMacro(Self);
90 
93 
95  using InputPixelType = typename InputImageType::PixelType;
96  using OperatorValueType = TOperatorValueType;
97  using OutputValueType = TOutputValueType;
98  using OutputPixelType = typename OutputImageType::PixelType;
101 
108  void
109  GenerateInputRequestedRegion() override;
110 
113  void
115  {
116  this->SetUseImageSpacing(true);
117  }
118 
121  void
123  {
124  this->SetUseImageSpacing(false);
125  }
126 
129  itkSetMacro(UseImageSpacing, bool);
130  itkGetConstMacro(UseImageSpacing, bool);
131  itkBooleanMacro(UseImageSpacing);
132 
134  void
135  OverrideBoundaryCondition(ImageBoundaryCondition<TInputImage> * boundaryCondition);
136 
137 #ifdef ITK_USE_CONCEPT_CHECKING
138  // Begin concept checking
140  itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputValueType>));
141  // End concept checking
142 #endif
143 
154  itkSetMacro(UseImageDirection, bool);
155  itkGetConstMacro(UseImageDirection, bool);
156  itkBooleanMacro(UseImageDirection);
158 
159 protected:
161  ~GradientImageFilter() override;
162  void
163  PrintSelf(std::ostream & os, Indent indent) const override;
164 
175  void
176  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
177 
178 
179 private:
180  void
181  GenerateOutputInformation() override;
182 
183  // An overloaded method which may transform the gradient to a
184  // physical vector and converts to the correct output pixel type.
185  template <typename TValue>
186  void
188  {
189  if (this->m_UseImageDirection)
190  {
191  CovariantVectorType physicalGradient;
192  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient);
193  it.Set(OutputPixelType(physicalGradient.GetDataPointer(), InputImageDimension, false));
194  }
195  else
196  {
197  it.Set(OutputPixelType(gradient.GetDataPointer(), InputImageDimension, false));
198  }
199  }
200 
201  template <typename T>
202  void
204  {
205  // This uses the more efficient set by reference method
206  if (this->m_UseImageDirection)
207  {
208  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value());
209  }
210  else
211  {
212  it.Value() = gradient;
213  }
214  }
215 
216 
218 
219  // flag to take or not the image direction into account
220  // when computing the derivatives.
222 
223  // allow setting the the m_BoundaryCondition
225 };
226 } // end namespace itk
227 
228 #ifndef ITK_MANUAL_INSTANTIATION
229 # include "itkGradientImageFilter.hxx"
230 #endif
231 
232 #endif
itk::GradientImageFilter::SetUseImageSpacingOn
void SetUseImageSpacingOn()
Definition: itkGradientImageFilter.h:114
itk::GradientImageFilter::m_UseImageDirection
bool m_UseImageDirection
Definition: itkGradientImageFilter.h:221
itk::GradientImageFilter::InputImageType
TInputImage InputImageType
Definition: itkGradientImageFilter.h:77
itk::GradientImageFilter::SetUseImageSpacingOff
void SetUseImageSpacingOff()
Definition: itkGradientImageFilter.h:122
itk::GradientImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkGradientImageFilter.h:78
itkCovariantVector.h
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:712
itk::GradientImageFilter::OutputImageType
TOutputImageType OutputImageType
Definition: itkGradientImageFilter.h:79
itk::VectorImage
Templated n-dimensional vector image class.
Definition: itkImageAlgorithm.h:29
itk::ImageConstIterator::GetImage
const ImageType * GetImage() const
Definition: itkImageConstIterator.h:336
itk::GradientImageFilter::m_UseImageSpacing
bool m_UseImageSpacing
Definition: itkGradientImageFilter.h:217
itk::SmartPointer< Self >
itkImageRegionIterator.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::GradientImageFilter::m_BoundaryCondition
ImageBoundaryCondition< TInputImage, TInputImage > * m_BoundaryCondition
Definition: itkGradientImageFilter.h:224
itk::FixedArray::GetDataPointer
ValueType * GetDataPointer()
Definition: itkFixedArray.h:313
itk::ImageBoundaryCondition
A virtual base object that defines an interface to a class of boundary condition objects for use by n...
Definition: itkImageBoundaryCondition.h:52
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:78
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::GradientImageFilter::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkGradientImageFilter.h:100
itkImageToImageFilter.h
itk::GradientImageFilter
Computes the gradient of an image using directional derivatives.
Definition: itkGradientImageFilter.h:66
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::GradientImageFilter::OutputValueType
TOutputValueType OutputValueType
Definition: itkGradientImageFilter.h:97
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Concept::Convertible
Definition: itkConceptChecking.h:214
itk::GradientImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkGradientImageFilter.h:95
itk::GradientImageFilter::SetOutputPixel
void SetOutputPixel(ImageRegionIterator< VectorImage< TValue, OutputImageDimension >> &it, CovariantVectorType &gradient)
Definition: itkGradientImageFilter.h:187
itk::GradientImageFilter::SetOutputPixel
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
Definition: itkGradientImageFilter.h:203
itk::GradientImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkGradientImageFilter.h:98
itk::GradientImageFilter::OperatorValueType
TOperatorValueType OperatorValueType
Definition: itkGradientImageFilter.h:96
itk::ImageRegionIterator::Value
PixelType & Value()
Definition: itkImageRegionIterator.h:123
itk::GradientImageFilter::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkGradientImageFilter.h:80