ITK  5.2.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  * 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 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 
131  using SizeType = typename Superclass::SizeType;
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  freqInd.Fill(0);
183  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
184  {
185  if (this->m_PositionIndex[dim] <= m_LargestPositiveFrequencyIndex[dim])
186  {
187  freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
188  }
189  else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
190  {
191  freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
192  }
193  }
194  return freqInd;
195  }
196 
217  GetFrequency() const
218  {
219  FrequencyType freq;
220  IndexType freqInd = this->GetFrequencyBin();
222 
223  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
224  {
225  freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
226  }
227  return freq;
228  }
229 
232  {
233  FrequencyValueType w2(0);
234  FrequencyType w(this->GetFrequency());
235 
236  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
237  {
238  w2 += w[dim] * w[dim];
239  }
240  return w2;
241  }
242 
252  itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
253 
255  itkGetConstReferenceMacro(MinIndex, IndexType);
256 
258  itkGetConstReferenceMacro(MaxIndex, IndexType);
259 
261  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
262 
269  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
270 
276  void
278  {
279  this->m_ActualXDimensionIsOdd = value;
280  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
281  auto size_estimated = 2 * (sizeImage[0] - 1);
282  size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
283  this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
284  }
285  itkGetMacro(ActualXDimensionIsOdd, bool);
286  itkBooleanMacro(ActualXDimensionIsOdd);
288 
289 private:
293  void
295  {
296  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
297  this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
298  this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
299  for (unsigned int dim = 0; dim < ImageType::ImageDimension; dim++)
300  {
302  static_cast<FrequencyValueType>(this->m_MinIndex[dim] + sizeImage[dim] / 2);
303  // Set frequency metadata.
304  // Origin of frequencies is zero after a FFT.
305  this->m_FrequencyOrigin[dim] = 0.0;
306  // SamplingFrequency = 1.0 / SpatialImageSpacing
307  // Freq_BinSize = SamplingFrequency / Size
308  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
309  }
310  // Corrections for Hermitian
311  // The fastest index has no negative frequencies.
312  this->m_LargestPositiveFrequencyIndex[0] = static_cast<FrequencyValueType>(this->m_MaxIndex[0]);
313  // In fastest dimension only:
314  // Size_estimated_original = 2 * (Size_current - 1 )
315  // Where size_current is the size of the output of RealToHalfHermitianFFT
316  // Ex: Size Original = 10, Current = 6, Estimated = 10.
317  // Size Original = 11, Current = 6, Estimated = 10.
318  auto size_estimated = 2 * (sizeImage[0] - 1);
319  size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
320  this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
321  }
323 
329  bool m_ActualXDimensionIsOdd{ false };
330 };
331 } // end namespace itk
332 #endif
itk::ImageRegionConstIteratorWithIndex::PixelType
typename Superclass::PixelType PixelType
Definition: itkImageRegionConstIteratorWithIndex.h:151
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyType
typename ImageType::SpacingType FrequencyType
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:141
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_MaxIndex
IndexType m_MaxIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:326
itk::ImageConstIteratorWithIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itkImageRegionConstIteratorWithIndex.h
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::SetActualXDimensionIsOdd
void SetActualXDimensionIsOdd(bool value)
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:277
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:327
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::IndexType
typename Superclass::IndexType IndexType
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:130
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::Init
void Init()
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:294
itk::ImageConstIteratorWithIndex::m_Image
TImage::ConstWeakPointer m_Image
Definition: itkImageConstIteratorWithIndex.h:296
itk::ImageRegionConstIteratorWithIndex::PixelContainerPointer
typename Superclass::PixelContainerPointer PixelContainerPointer
Definition: itkImageRegionConstIteratorWithIndex.h:149
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_LargestPositiveFrequencyIndex
IndexType m_LargestPositiveFrequencyIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:324
itk::ImageConstIteratorWithIndex::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::ImageRegionConstIteratorWithIndex::ImageType
typename Superclass::ImageType ImageType
Definition: itkImageRegionConstIteratorWithIndex.h:147
itk::ImageConstIteratorWithIndex::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::ImageRegionConstIteratorWithIndex::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkImageRegionConstIteratorWithIndex.h:145
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:329
itk::ImageRegionConstIteratorWithIndex::RegionType
typename Superclass::RegionType RegionType
Definition: itkImageRegionConstIteratorWithIndex.h:146
itk::ImageConstIteratorWithIndex::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_MinIndex
IndexType m_MinIndex
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:325
itk::ImageRegionConstIteratorWithIndex::IndexType
typename Superclass::IndexType IndexType
Definition: itkImageRegionConstIteratorWithIndex.h:143
itk::ImageConstIteratorWithIndex
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
Definition: itkImageConstIteratorWithIndex.h:92
itk::ImageRegionConstIteratorWithIndex::AccessorType
typename Superclass::AccessorType AccessorType
Definition: itkImageRegionConstIteratorWithIndex.h:152
itk::ImageRegionConstIteratorWithIndex::InternalPixelType
typename Superclass::InternalPixelType InternalPixelType
Definition: itkImageRegionConstIteratorWithIndex.h:150
itk::ImageRegionConstIteratorWithIndex::SizeType
typename Superclass::SizeType SizeType
Definition: itkImageRegionConstIteratorWithIndex.h:144
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyBin
IndexType GetFrequencyBin() const
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:179
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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:217
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex
FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:153
itk::FrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencySpacing
FrequencyType m_FrequencySpacing
Definition: itkFrequencyHalfHermitianFFTLayoutImageRegionConstIteratorWithIndex.h:328
itk::ImageConstIteratorWithIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithIndex.h:298
itk::ImageRegionConstIteratorWithIndex::PixelContainer
typename Superclass::PixelContainer PixelContainer
Definition: itkImageRegionConstIteratorWithIndex.h:148
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:231
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