ITK  5.4.0
Insight Toolkit
itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.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  * 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 itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex_h
19 #define itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex_h
20 
22 
23 namespace itk
24 {
114 template <typename TImage>
116  : public ImageRegionConstIteratorWithIndex<TImage>
117 {
118 public:
119 
123 
125  using typename Superclass::IndexType;
126  using typename Superclass::SizeType;
127  using typename Superclass::OffsetType;
128  using typename Superclass::RegionType;
129  using typename Superclass::ImageType;
130  using typename Superclass::PixelContainer;
131  using typename Superclass::PixelContainerPointer;
132  using typename Superclass::InternalPixelType;
133  using typename Superclass::PixelType;
134  using typename Superclass::AccessorType;
135 
136  using FrequencyType = typename ImageType::SpacingType;
137  using FrequencyValueType = typename ImageType::SpacingValueType;
141  {
142  this->Init();
143  }
144 
148  : ImageRegionConstIteratorWithIndex<TImage>(ptr, region)
149  {
150  this->Init();
151  }
152 
161  {
162  this->Init();
163  }
164 
165  /*
166  * Image Index [0, N - 1] returns [-N/2 + 1, -1] (negative) union [0 to N/2] (positive). So index N/2 + 1 returns the
167  * bin 0. It is a shift by -N/2 + 1, from [0, N-1] to [-N/2 + 1, N/2] If first index of the image is not zero, it
168  * stills returns values in the same range.
169  */
170  IndexType
172  {
173  IndexType freqInd;
174 
175  freqInd.Fill(0);
176  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
177  {
178  freqInd[dim] = this->m_PositionIndex[dim] - this->m_ZeroFrequencyIndex[dim];
179  }
180  return freqInd;
181  }
182 
193  FrequencyType
194  GetFrequency() const
195  {
196  FrequencyType freq;
197  IndexType freqInd = this->GetFrequencyBin();
200  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
201  {
202  freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
203  }
204  return freq;
205  }
206 
207  FrequencyValueType
209  {
210  FrequencyValueType w2(0);
211  FrequencyType w(this->GetFrequency());
212 
213  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
214  {
215  w2 += w[dim] * w[dim];
216  }
217  return w2;
218  }
219 
226  itkGetConstReferenceMacro(ZeroFrequencyIndex, IndexType);
227 
229  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
230 
237  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
238 
241  void
243  {
244  this->m_ActualXDimensionIsOdd = value;
245  };
246  itkGetMacro(ActualXDimensionIsOdd, bool);
247  itkBooleanMacro(ActualXDimensionIsOdd);
250 private:
253  void
255  {
256  IndexType minIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
257  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
258  for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
259  {
260  this->m_ZeroFrequencyIndex[dim] =
261  static_cast<FrequencyValueType>(minIndex[dim] + std::floor(sizeImage[dim] / 2.0));
262  // Set frequency metadata.
263  // Origin of frequencies is zero in the standard layout of a FFT output.
264  this->m_FrequencyOrigin[dim] = 0.0;
265  // SamplingFrequency = 1.0 / SpatialImageSpacing
266  // Freq_BinSize = SamplingFrequency / Size
267  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
268  }
269  }
276 };
277 } // end namespace itk
278 #endif
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::Init
void Init()
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:254
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::SetActualXDimensionIsOdd
void SetActualXDimensionIsOdd(bool value)
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:242
itk::ImageConstIteratorWithIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itkImageRegionConstIteratorWithIndex.h
itk::ImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
Definition: itkImageRegionConstIteratorWithIndex.h:130
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex
FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex(const Superclass &it)
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:159
itk::ImageConstIteratorWithIndex::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageConstIteratorWithIndex::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:274
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex
FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex()
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:139
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::m_ZeroFrequencyIndex
IndexType m_ZeroFrequencyIndex
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:272
itk::ImageConstIteratorWithIndex::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkImageConstIteratorWithIndex.h:125
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencyOrigin
FrequencyType m_FrequencyOrigin
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:273
itk::Index::GetIndex
const IndexValueType * GetIndex() const
Definition: itkIndex.h:232
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::FrequencyType
typename ImageType::SpacingType FrequencyType
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:136
itk::ImageConstIteratorWithIndex::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyModuloSquare
FrequencyValueType GetFrequencyModuloSquare() const
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:208
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::FrequencyValueType
typename ImageType::SpacingValueType FrequencyValueType
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:137
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex
FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:147
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyBin
IndexType GetFrequencyBin() const
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:171
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::m_ActualXDimensionIsOdd
bool m_ActualXDimensionIsOdd
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:275
itk::ImageConstIteratorWithIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:115
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencySpacing
FrequencyType m_FrequencySpacing
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:274
itk::ImageConstIteratorWithIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::FrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex::GetFrequency
FrequencyType GetFrequency() const
Definition: itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.h:194
itk::ImageConstIteratorWithIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136