ITK  5.2.0
Insight Toolkit
itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.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 itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
19 #define itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
20 
22 
23 namespace itk
24 {
114 template <typename TImage>
116 {
117 public:
118 
122 
125  using SizeType = typename Superclass::SizeType;
134 
135  using FrequencyType = typename ImageType::SpacingType;
136  using FrequencyValueType = typename ImageType::SpacingValueType;
140  {
141  this->Init();
142  }
143 
147  : ImageRegionConstIteratorWithIndex<TImage>(ptr, region)
148  {
149  this->Init();
150  }
151 
160  {
161  this->Init();
162  }
163 
164  /*
165  * Image Index [0, N - 1] returns [0 to N/2] (positive) union [-N/2 + 1, -1] (negative). So index N/2 + 1 returns the
166  * bin -N/2 + 1. If first index of the image is not zero, it stills returns values in the same range. f = [0, 1, ...,
167  * N/2-1, -N/2, ..., -1] if N is even f = [0, 1, ..., (N-1)/2, -(N-1)/2, ..., -1] if N is odd
168  */
169  IndexType
171  {
172  IndexType freqInd;
173 
174  freqInd.Fill(0);
175  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
176  {
177  if (this->m_PositionIndex[dim] <= m_LargestPositiveFrequencyIndex[dim])
178  {
179  freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
180  }
181  else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
182  {
183  freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
184  }
185  }
186  return freqInd;
187  }
188 
209  GetFrequency() const
210  {
211  FrequencyType freq;
212  IndexType freqInd = this->GetFrequencyBin();
214 
215  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
216  {
217  freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
218  }
219  return freq;
220  }
221 
224  {
225  FrequencyValueType w2(0);
226  FrequencyType w(this->GetFrequency());
227 
228  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
229  {
230  w2 += w[dim] * w[dim];
231  }
232  return w2;
233  }
234 
244  itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
245 
247  itkGetConstReferenceMacro(MinIndex, IndexType);
248 
250  itkGetConstReferenceMacro(MaxIndex, IndexType);
251 
253  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
254 
261  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
262 
265  void
267  {
268  this->m_ActualXDimensionIsOdd = value;
269  };
270  itkGetMacro(ActualXDimensionIsOdd, bool);
271  itkBooleanMacro(ActualXDimensionIsOdd);
273 
274 private:
278  void
280  {
281  SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
282  this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
283  this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
284  for (unsigned int dim = 0; dim < ImageType::ImageDimension; dim++)
285  {
287  static_cast<FrequencyValueType>(this->m_MinIndex[dim] + std::floor(sizeImage[dim] / 2.0));
288  // Set frequency metadata.
289  // Origin of frequencies is zero after a FFT.
290  this->m_FrequencyOrigin[dim] = 0.0;
291  // SamplingFrequency = 1.0 / SpatialImageSpacing
292  // Freq_BinSize = SamplingFrequency / Size
293  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
294  }
295  }
297 
304 };
305 } // end namespace itk
306 #endif
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyModuloSquare
FrequencyValueType GetFrequencyModuloSquare() const
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:223
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:115
itk::ImageRegionConstIteratorWithIndex::PixelType
typename Superclass::PixelType PixelType
Definition: itkImageRegionConstIteratorWithIndex.h:151
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_MaxIndex
IndexType m_MaxIndex
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:300
itk::ImageConstIteratorWithIndex::SizeType
typename TImage::SizeType SizeType
Definition: itkImageConstIteratorWithIndex.h:109
itkImageRegionConstIteratorWithIndex.h
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_ActualXDimensionIsOdd
bool m_ActualXDimensionIsOdd
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:303
itk::ImageRegionConstIteratorWithIndex
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
Definition: itkImageRegionConstIteratorWithIndex.h:130
itk::ImageConstIteratorWithIndex::m_Image
TImage::ConstWeakPointer m_Image
Definition: itkImageConstIteratorWithIndex.h:296
itk::ImageRegionConstIteratorWithIndex::PixelContainerPointer
typename Superclass::PixelContainerPointer PixelContainerPointer
Definition: itkImageRegionConstIteratorWithIndex.h:149
itk::ImageConstIteratorWithIndex::PixelContainerPointer
typename PixelContainer::Pointer PixelContainerPointer
Definition: itkImageConstIteratorWithIndex.h:122
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::GetFrequencyBin
IndexType GetFrequencyBin() const
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:170
itk::ImageRegionConstIteratorWithIndex::ImageType
typename Superclass::ImageType ImageType
Definition: itkImageRegionConstIteratorWithIndex.h:147
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::FrequencyType
typename ImageType::SpacingType FrequencyType
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:135
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::Init
void Init()
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:279
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::FrequencyFFTLayoutImageRegionConstIteratorWithIndex
FrequencyFFTLayoutImageRegionConstIteratorWithIndex(const TImage *ptr, const RegionType &region)
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:146
itk::ImageConstIteratorWithIndex::PixelType
typename TImage::PixelType PixelType
Definition: itkImageConstIteratorWithIndex.h:128
itk::ImageRegionConstIteratorWithIndex::OffsetType
typename Superclass::OffsetType OffsetType
Definition: itkImageRegionConstIteratorWithIndex.h:145
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::FrequencyFFTLayoutImageRegionConstIteratorWithIndex
FrequencyFFTLayoutImageRegionConstIteratorWithIndex(const Superclass &it)
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:158
itk::ImageConstIteratorWithIndex::IndexType
typename TImage::IndexType IndexType
Definition: itkImageConstIteratorWithIndex.h:105
itk::ImageConstIteratorWithIndex::InternalPixelType
typename TImage::InternalPixelType InternalPixelType
Definition: itkImageConstIteratorWithIndex.h:125
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_LargestPositiveFrequencyIndex
IndexType m_LargestPositiveFrequencyIndex
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:298
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::GetFrequency
FrequencyType GetFrequency() const
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:209
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::SetActualXDimensionIsOdd
void SetActualXDimensionIsOdd(bool value)
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:266
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::FrequencyFFTLayoutImageRegionConstIteratorWithIndex
FrequencyFFTLayoutImageRegionConstIteratorWithIndex()
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:138
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::FrequencyValueType
typename ImageType::SpacingValueType FrequencyValueType
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:136
itk::ImageRegionConstIteratorWithIndex::RegionType
typename Superclass::RegionType RegionType
Definition: itkImageRegionConstIteratorWithIndex.h:146
itk::ImageConstIteratorWithIndex::AccessorType
typename TImage::AccessorType AccessorType
Definition: itkImageConstIteratorWithIndex.h:132
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::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_MinIndex
IndexType m_MinIndex
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:299
itk::ImageRegionConstIteratorWithIndex::AccessorType
typename Superclass::AccessorType AccessorType
Definition: itkImageRegionConstIteratorWithIndex.h:152
itk::ImageRegionConstIteratorWithIndex::InternalPixelType
typename Superclass::InternalPixelType InternalPixelType
Definition: itkImageRegionConstIteratorWithIndex.h:150
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencyOrigin
FrequencyType m_FrequencyOrigin
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:301
itk::ImageRegionConstIteratorWithIndex::SizeType
typename Superclass::SizeType SizeType
Definition: itkImageRegionConstIteratorWithIndex.h:144
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ImageConstIteratorWithIndex::RegionType
typename TImage::RegionType RegionType
Definition: itkImageConstIteratorWithIndex.h:113
itk::ImageConstIteratorWithIndex::m_PositionIndex
IndexType m_PositionIndex
Definition: itkImageConstIteratorWithIndex.h:298
itk::ImageRegionConstIteratorWithIndex::PixelContainer
typename Superclass::PixelContainer PixelContainer
Definition: itkImageRegionConstIteratorWithIndex.h:148
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::IndexType
typename Superclass::IndexType IndexType
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:124
itk::ImageConstIteratorWithIndex::ImageType
TImage ImageType
Definition: itkImageConstIteratorWithIndex.h:116
itk::ImageConstIteratorWithIndex::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageConstIteratorWithIndex.h:121
itk::FrequencyFFTLayoutImageRegionConstIteratorWithIndex::m_FrequencySpacing
FrequencyType m_FrequencySpacing
Definition: itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h:302
itk::ImageConstIteratorWithIndex::OffsetType
typename TImage::OffsetType OffsetType
Definition: itkImageConstIteratorWithIndex.h:136