|
| 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 | + * https://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 itkHigherOrderAccurateDerivativeImageFilter_h |
| 19 | +#define itkHigherOrderAccurateDerivativeImageFilter_h |
| 20 | + |
| 21 | +#include "itkImageToImageFilter.h" |
| 22 | + |
| 23 | +namespace itk |
| 24 | +{ |
| 25 | + |
| 26 | +/** \class HigherOrderAccurateDerivativeImageFilter |
| 27 | + * \brief Computes the higher order accurate directional derivative of an image. |
| 28 | + * The directional derivative at each pixel location is computed by convolution |
| 29 | + * with a higher order accurate derivative operator of user-specified order. |
| 30 | + * |
| 31 | + * SetOrder() specifies the order of the derivative. |
| 32 | + * |
| 33 | + * SetDirection() specifies the direction of the derivative with respect to the |
| 34 | + * coordinate axes of the image. |
| 35 | + * |
| 36 | + * To specify the order of accuracy, use SetOrderOfAccuracy(). The |
| 37 | + * approximation will be accurate to two times the OrderOfAccuracy in terms of |
| 38 | + * Taylor series terms. |
| 39 | + * |
| 40 | + * \sa Image |
| 41 | + * \sa Neighborhood |
| 42 | + * \sa NeighborhoodOperator |
| 43 | + * \sa NeighborhoodIterator |
| 44 | + * |
| 45 | + * \ingroup ImageFeatureExtraction |
| 46 | + * \ingroup HigherOrderAccurateGradient |
| 47 | + */ |
| 48 | +template <typename TInputImage, typename TOutputImage> |
| 49 | +class HigherOrderAccurateDerivativeImageFilter : public ImageToImageFilter<TInputImage, TOutputImage> |
| 50 | +{ |
| 51 | +public: |
| 52 | + ITK_DISALLOW_COPY_AND_MOVE(HigherOrderAccurateDerivativeImageFilter); |
| 53 | + |
| 54 | + /** Standard class type alias. */ |
| 55 | + using Self = HigherOrderAccurateDerivativeImageFilter; |
| 56 | + using Superclass = ImageToImageFilter<TInputImage, TOutputImage>; |
| 57 | + using Pointer = SmartPointer<Self>; |
| 58 | + using ConstPointer = SmartPointer<const Self>; |
| 59 | + |
| 60 | + /** Extract some information from the image types. Dimensionality |
| 61 | + * of the two images is assumed to be the same. */ |
| 62 | + using OutputPixelType = typename TOutputImage::PixelType; |
| 63 | + using OutputInternalPixelType = typename TOutputImage::InternalPixelType; |
| 64 | + using InputPixelType = typename TInputImage::PixelType; |
| 65 | + using InputInternalPixelType = typename TInputImage::InternalPixelType; |
| 66 | + |
| 67 | + /** Extract some information from the image types. Dimensionality |
| 68 | + * of the two images is assumed to be the same. */ |
| 69 | + static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension; |
| 70 | + |
| 71 | + /** Image type alias support. */ |
| 72 | + using InputImageType = TInputImage; |
| 73 | + using OutputImageType = TOutputImage; |
| 74 | + |
| 75 | + /** Method for creation through the object factory. */ |
| 76 | + itkNewMacro(Self); |
| 77 | + |
| 78 | + /** Run-time type information (and related methods). */ |
| 79 | + itkTypeMacro(HigherOrderAccurateDerivativeImageFilter, ImageToImageFilter); |
| 80 | + |
| 81 | + /** The output pixel type must be signed. */ |
| 82 | +#ifdef ITK_USE_CONCEPT_CHECKING |
| 83 | + /** Begin concept checking */ |
| 84 | + itkConceptMacro(SignedOutputPixelType, (Concept::Signed<OutputPixelType>)); |
| 85 | + /** End concept checking */ |
| 86 | +#endif |
| 87 | + |
| 88 | + /** Standard get/set macros for filter parameters. */ |
| 89 | + itkSetMacro(Order, unsigned int); |
| 90 | + itkGetConstMacro(Order, unsigned int); |
| 91 | + itkSetMacro(OrderOfAccuracy, unsigned int); |
| 92 | + itkGetConstMacro(OrderOfAccuracy, unsigned int); |
| 93 | + itkSetMacro(Direction, unsigned int); |
| 94 | + itkGetConstMacro(Direction, unsigned int); |
| 95 | + |
| 96 | + /** Use the image spacing information in calculations. Use this option if you |
| 97 | + * want derivatives in physical space. Default is UseImageSpacingOn. */ |
| 98 | + void |
| 99 | + SetUseImageSpacingOn() |
| 100 | + { |
| 101 | + this->SetUseImageSpacing(true); |
| 102 | + } |
| 103 | + |
| 104 | + /** Ignore the image spacing. Use this option if you want derivatives in |
| 105 | + isotropic pixel space. Default is UseImageSpacingOn. */ |
| 106 | + void |
| 107 | + SetUseImageSpacingOff() |
| 108 | + { |
| 109 | + this->SetUseImageSpacing(false); |
| 110 | + } |
| 111 | + |
| 112 | + /** Set/Get whether or not the filter will use the spacing of the input |
| 113 | + image in its calculations */ |
| 114 | + itkSetMacro(UseImageSpacing, bool); |
| 115 | + itkGetConstMacro(UseImageSpacing, bool); |
| 116 | + |
| 117 | +protected: |
| 118 | + HigherOrderAccurateDerivativeImageFilter() = default; |
| 119 | + |
| 120 | + ~HigherOrderAccurateDerivativeImageFilter() override = default; |
| 121 | + void |
| 122 | + PrintSelf(std::ostream & os, Indent indent) const override; |
| 123 | + |
| 124 | + /** HigherOrderAccurateDerivativeImageFilter needs a larger input requested region than |
| 125 | + * the output requested region (larger in the direction of the |
| 126 | + * derivative). As such, HigherOrderAccurateDerivativeImageFilter needs to provide an |
| 127 | + * implementation for GenerateInputRequestedRegion() in order to |
| 128 | + * inform the pipeline execution model. |
| 129 | + * |
| 130 | + * \sa ImageToImageFilter::GenerateInputRequestedRegion() */ |
| 131 | + void |
| 132 | + GenerateInputRequestedRegion() override; |
| 133 | + |
| 134 | + /** Standard pipeline method. While this class does not implement a |
| 135 | + * ThreadedGenerateData(), its GenerateData() delegates all |
| 136 | + * calculations to an NeighborhoodOperatorImageFilter. Since the |
| 137 | + * NeighborhoodOperatorImageFilter is multithreaded, this filter is |
| 138 | + * multithreaded by default. */ |
| 139 | + void |
| 140 | + GenerateData() override; |
| 141 | + |
| 142 | +private: |
| 143 | + /** The order of the derivative. */ |
| 144 | + unsigned int m_Order{ 1 }; |
| 145 | + |
| 146 | + /** Order of accuracy. */ |
| 147 | + unsigned int m_OrderOfAccuracy{ 2 }; |
| 148 | + |
| 149 | + /** The direction of the derivative. */ |
| 150 | + unsigned int m_Direction{ 0 }; |
| 151 | + |
| 152 | + bool m_UseImageSpacing{ true }; |
| 153 | +}; |
| 154 | + |
| 155 | +} // end namespace itk |
| 156 | + |
| 157 | +#ifndef ITK_MANUAL_INSTANTIATION |
| 158 | +# include "itkHigherOrderAccurateDerivativeImageFilter.hxx" |
| 159 | +#endif |
| 160 | + |
| 161 | +#endif |
0 commit comments