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 itkGaborImageSource_h
19 #define itkGaborImageSource_h
20 
21 #include "itkGenerateImageSource.h"
22 #include "itkFixedArray.h"
23 
24 namespace itk
25 {
26 /** \class GaborImageSource
27  * \brief Generate an n-dimensional image of a Gabor filter.
28  *
29  * GaborImageSource generates an image of either the real
30  * (i.e. symmetric) or complex (i.e. antisymmetric) part
31  * of the Gabor filter with the orientation directed along
32  * the x-axis. The GaborKernelFunction is used to evaluate
33  * the contribution along the x-axis whereas a non-normalized
34  * 1-D Gaussian envelope provides the contribution in each of
35  * the remaining N dimensions. Orientation can be manipulated
36  * via the Transform classes of the toolkit.
37  *
38  * The output image may be of any dimension.
39  *
40  * This implementation was contributed as a paper to the Insight Journal
41  * https://hdl.handle.net/1926/500
42  *
43  * \ingroup DataSources
44  * \ingroup ITKImageSources
45  */
46 template< typename TOutputImage >
47 class ITK_TEMPLATE_EXPORT GaborImageSource:
48   public GenerateImageSource< TOutputImage >
49 {
50 public:
51   ITK_DISALLOW_COPY_AND_ASSIGN(GaborImageSource);
52 
53   /** Standard class type aliases. */
54   using Self = GaborImageSource;
55   using Superclass = GenerateImageSource< TOutputImage >;
56   using Pointer = SmartPointer< Self >;
57   using ConstPointer = SmartPointer< const Self >;
58 
59   /** Output image type alias */
60   using OutputImageType = TOutputImage;
61   using PixelType = typename OutputImageType::PixelType;
62   using RegionType = typename OutputImageType::RegionType;
63   using SpacingType = typename OutputImageType::SpacingType;
64   using PointType = typename OutputImageType::PointType;
65   using DirectionType = typename OutputImageType::DirectionType;
66 
67   using SizeType = typename RegionType::SizeType;
68 
69   /** Run-time type information (and related methods). */
70   itkTypeMacro(GaborImageSource, GenerateImageSource);
71 
72   /** Method for creation through the object factory. */
73   itkNewMacro(Self);
74 
75   /** Dimensionality of the output image */
76   static constexpr unsigned int ImageDimension = OutputImageType::ImageDimension;
77 
78   /** Type used to store gabor parameters. */
79   using ArrayType = FixedArray< double,
80                       Self::ImageDimension >;
81 
82   /** Set/Get the the standard deviation in each direction. */
83   itkSetMacro(Sigma, ArrayType);
84   itkGetConstReferenceMacro(Sigma, ArrayType);
85 
86   /** Set/Get the mean in each direction. */
87   itkSetMacro(Mean, ArrayType);
88   itkGetConstReferenceMacro(Mean, ArrayType);
89 
90   /** Set/Get the modulation frequency of the sine or cosine component. */
91   itkSetMacro(Frequency, double);
92   itkGetConstReferenceMacro(Frequency, double);
93 
94   /** Set/Get whether the evaluation is performed using the using the imaginary
95    * part. Default is false. */
96   itkSetMacro(CalculateImaginaryPart, bool);
97   itkGetConstReferenceMacro(CalculateImaginaryPart, bool);
98   itkBooleanMacro(CalculateImaginaryPart);
99 
100 protected:
101   GaborImageSource();
102   ~GaborImageSource() override = default;
103   void PrintSelf(std::ostream & os, Indent indent) const override;
104 
105   void GenerateData() override;
106 
107 private:
108   bool m_CalculateImaginaryPart{ false };
109 
110   double m_Frequency{ 0.4 };
111 
112   /** Evaluate using a stretched gabor filter (ensure zero dc response) */
113   double m_PhaseOffset{ 0.0 };
114 
115   ArrayType m_Sigma;
116 
117   ArrayType m_Mean;
118 };
119 } // end namespace itk
120 
121 #ifndef ITK_MANUAL_INSTANTIATION
122 #include "itkGaborImageSource.hxx"
123 #endif
124 
125 #endif
126