ITK  6.0.0
Insight Toolkit
itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.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 itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex_h
19 #define itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex_h
20 
22 
23 namespace itk
24 {
119 template <typename TImage>
121  : public ImageRegionConstIteratorWithIndex<TImage>
122 {
123 public:
124 
128 
130  using typename Superclass::IndexType;
131  using typename Superclass::SizeType;
132  using typename Superclass::OffsetType;
133  using typename Superclass::RegionType;
134  using typename Superclass::ImageType;
135  using typename Superclass::PixelContainer;
136  using typename Superclass::PixelContainerPointer;
137  using typename Superclass::InternalPixelType;
138  using typename Superclass::PixelType;
139  using typename Superclass::AccessorType;
140 
141  using FrequencyType = typename ImageType::SpacingType;
142  using FrequencyValueType = typename ImageType::SpacingValueType;
146 
147  {
148  this->Init();
149  }
150 
154  : ImageRegionConstIteratorWithIndex<TImage>(ptr, region)
155  {
156  this->Init();
157  }
158 
167  {
168  this->Init();
169  }
170 
171  /*
172  * Image Index [0, N - 1] returns [0 to N/2] (positive) union [-N/2 + 1, -1] (negative).
173  * So index N/2 + 1 returns the bin -N/2 + 1.
174  * If first index of the image is not zero, it stills returns values in the same range.
175  * f = [0, 1, ..., N/2-1, -N/2, ..., -1] if N is even
176  * f = [0, 1, ..., (N-1)/2, -(N-1)/2, ..., -1] if N is odd
177  */
178  IndexType
180  {
181  IndexType freqInd{};
182  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
183  {
184  if (this->m_PositionIndex[dim] <= m_LargestPositiveFrequencyIndex[dim])
185  {
186  freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
187  }
188  else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
189  {
190  freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
191  }
192  }
193  return freqInd;
194  }
195 
216  GetFrequency() const
217  {
218  FrequencyType freq;
219  IndexType freqInd = this->GetFrequencyBin();
222  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
223  {
224  freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
225  }
226  return freq;
227  }
228 
231  {
232  FrequencyValueType w2(0);
233  FrequencyType w(this->GetFrequency());
234 
235  for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
236  {
237  w2 += w[dim] * w[dim];
238  }
239  return w2;
240  }
241 
251  itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
252 
254  itkGetConstReferenceMacro(MinIndex, IndexType);
255 
257  itkGetConstReferenceMacro(MaxIndex, IndexType);
258 
260  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
261 
268  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
269 
275  void
277  {
278  this->m_ActualXDimensionIsOdd = value;
279  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
280  auto size_estimated = 2 * (sizeImage[0] - 1);
281  size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
282  this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
283  }
284  itkGetMacro(ActualXDimensionIsOdd, bool);
285  itkBooleanMacro(ActualXDimensionIsOdd);
288 private:
292  void
294  {
295  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
296  this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
297  this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
298  for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
299  {
301  static_cast<FrequencyValueType>(this->m_MinIndex[dim] + sizeImage[dim] / 2);
302  // Set frequency metadata.
303  // Origin of frequencies is zero after a FFT.
304  this->m_FrequencyOrigin[dim] = 0.0;
305  // SamplingFrequency = 1.0 / SpatialImageSpacing
306  // Freq_BinSize = SamplingFrequency / Size
307  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
308  }
309  // Corrections for Hermitian
310  // The fastest index has no negative frequencies.
311  this->m_LargestPositiveFrequencyIndex[0] = static_cast<FrequencyValueType>(this->m_MaxIndex[0]);
312  // In fastest dimension only:
313  // Size_estimated_original = 2 * (Size_current - 1 )
314  // Where size_current is the size of the output of RealToHalfHermitianFFT
315  // Ex: Size Original = 10, Current = 6, Estimated = 10.
316  // Size Original = 11, Current = 6, Estimated = 10.
317  auto size_estimated = 2 * (sizeImage[0] - 1);
318  size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
319  this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
320  }
328  bool m_ActualXDimensionIsOdd{ false };
329 };
330 } // end namespace itk
331 #endif
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyType
typename ImageType::SpacingType FrequencyType
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:141
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_MaxIndex
IndexType m_MaxIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:325
itk::ImageConstIteratorWithIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itkImageRegionConstIteratorWithIndex.h
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::SetActualXDimensionIsOdd
void SetActualXDimensionIsOdd(bool value)
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:276
itk::ImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
Definition: itkImageRegionConstIteratorWithIndex.h:130
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencyOrigin
FrequencyType m_FrequencyOrigin
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:326
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::Init
void Init()
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:293
itk::ImageConstIteratorWithIndex::m_Image
TImage::ConstWeakPointer m_Image
Definition: itkImageConstIteratorWithIndex.h:289
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_LargestPositiveFrequencyIndex
IndexType m_LargestPositiveFrequencyIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:323
itk::ImageConstIteratorWithIndex::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageConstIteratorWithIndex::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:120
itk::ImageConstIteratorWithIndex::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIteratorWithIndex.h:105
itk::ImageConstIteratorWithIndex::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkImageConstIteratorWithIndex.h:125
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_ActualXDimensionIsOdd
bool m_ActualXDimensionIsOdd
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:328
itk::ImageConstIteratorWithIndex::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_MinIndex
IndexType m_MinIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:324
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyBin
IndexType GetFrequencyBin() const
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:179
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex
FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex(const Superclass &it)
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:165
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex
FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex()
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:144
itk::ImageConstIteratorWithIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::GetFrequency
FrequencyType GetFrequency() const
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:216
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex
FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:153
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencySpacing
FrequencyType m_FrequencySpacing
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:327
itk::ImageConstIteratorWithIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithIndex.h:291
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::GetActualXDimensionIsOdd
virtual bool GetActualXDimensionIsOdd()
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyValueType
typename ImageType::SpacingValueType FrequencyValueType
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:142
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyModuloSquare
FrequencyValueType GetFrequencyModuloSquare() const
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:230
itk::ImageConstIteratorWithIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::ImageConstIteratorWithIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136