ITK  5.3.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_MOVE(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 
116  itkSetMacro(UseImageSpacing, bool);
117  itkGetConstMacro(UseImageSpacing, bool);
118  itkBooleanMacro(UseImageSpacing);
120 
121 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
122 
125  void
126  SetUseImageSpacingOn()
127  {
128  this->SetUseImageSpacing(true);
129  }
130 
134  void
135  SetUseImageSpacingOff()
136  {
137  this->SetUseImageSpacing(false);
138  }
139 #endif
140 
142  void
143  OverrideBoundaryCondition(ImageBoundaryCondition<TInputImage> * boundaryCondition);
144 
145 #ifdef ITK_USE_CONCEPT_CHECKING
146  // Begin concept checking
147  itkConceptMacro(InputConvertibleToOutputCheck, (Concept::Convertible<InputPixelType, OutputValueType>));
148  itkConceptMacro(OutputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputValueType>));
149  // End concept checking
150 #endif
151 
162  itkSetMacro(UseImageDirection, bool);
163  itkGetConstMacro(UseImageDirection, bool);
164  itkBooleanMacro(UseImageDirection);
166 
167 protected:
168  GradientImageFilter();
169  ~GradientImageFilter() override;
170  void
171  PrintSelf(std::ostream & os, Indent indent) const override;
172 
183  void
184  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
185 
186 
187 private:
188  void
189  GenerateOutputInformation() override;
190 
191  // An overloaded method which may transform the gradient to a
192  // physical vector and converts to the correct output pixel type.
193  template <typename TValue>
194  void
196  {
197  if (this->m_UseImageDirection)
198  {
199  CovariantVectorType physicalGradient;
200  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, physicalGradient);
201  it.Set(OutputPixelType(physicalGradient.GetDataPointer(), InputImageDimension, false));
202  }
203  else
204  {
205  it.Set(OutputPixelType(gradient.GetDataPointer(), InputImageDimension, false));
206  }
207  }
208 
209  template <typename T>
210  void
212  {
213  // This uses the more efficient set by reference method
214  if (this->m_UseImageDirection)
215  {
216  it.GetImage()->TransformLocalVectorToPhysicalVector(gradient, it.Value());
217  }
218  else
219  {
220  it.Value() = gradient;
221  }
222  }
223 
224 
226 
227  // flag to take or not the image direction into account
228  // when computing the derivatives.
230 
231  // allow setting the the m_BoundaryCondition
233 };
234 } // end namespace itk
235 
236 #ifndef ITK_MANUAL_INSTANTIATION
237 # include "itkGradientImageFilter.hxx"
238 #endif
239 
240 #endif
itk::GradientImageFilter::m_UseImageDirection
bool m_UseImageDirection
Definition: itkGradientImageFilter.h:229
itk::GradientImageFilter::InputImageType
TInputImage InputImageType
Definition: itkGradientImageFilter.h:77
itk::GradientImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkGradientImageFilter.h:78
itkCovariantVector.h
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:225
itk::SmartPointer< Self >
itkImageRegionIterator.h
itk::GradientImageFilter::m_BoundaryCondition
ImageBoundaryCondition< TInputImage, TInputImage > * m_BoundaryCondition
Definition: itkGradientImageFilter.h:232
itk::FixedArray::GetDataPointer
ValueType * GetDataPointer()
Definition: itkFixedArray.h:313
itk::ImageBoundaryCondition< TInputImage, TInputImage >
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:80
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:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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:195
itk::GradientImageFilter::SetOutputPixel
void SetOutputPixel(ImageRegionIterator< T > &it, CovariantVectorType &gradient)
Definition: itkGradientImageFilter.h:211
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:125
itk::GradientImageFilter::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkGradientImageFilter.h:80