ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h
Go to the documentation of this file.
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 itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
19 #define itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
20 
22 
23 namespace itk
24 {
113 template< typename TImage >
115  public ImageRegionConstIteratorWithIndex< TImage >
116 {
117 public:
121 
124  using SizeType = typename Superclass::SizeType;
133 
134  using FrequencyType = typename ImageType::SpacingType;
135  using FrequencyValueType = typename ImageType::SpacingValueType;
139  {
140  this->Init();
141  }
142 
146  ImageRegionConstIteratorWithIndex< TImage >(ptr, region)
147  {
148  this->Init();
149  }
150 
159  {
160  this->Init();
161  }
162 
163  /*
164  * Image Index [0, N - 1] returns [0 to N/2] (positive) union [-N/2 + 1, -1] (negative). So index N/2 + 1 returns the bin -N/2 + 1.
165  * If first index of the image is not zero, it stills returns values in the same range.
166  * f = [0, 1, ..., N/2-1, -N/2, ..., -1] if N is even
167  * f = [0, 1, ..., (N-1)/2, -(N-1)/2, ..., -1] if N is odd
168  */
170  {
171  IndexType freqInd;
172 
173  freqInd.Fill(0);
174  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
175  {
176  if (this->m_PositionIndex[dim] <= m_LargestPositiveFrequencyIndex[dim])
177  {
178  freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
179  }
180  else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
181  {
182  freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
183  }
184  }
185  return freqInd;
186  }
187 
208  {
209  FrequencyType freq;
210  IndexType freqInd = this->GetFrequencyBin();
212 
213  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
214  {
215  freq[dim] = this->m_FrequencyOrigin[dim]
216  + this->m_FrequencySpacing[dim] * freqInd[dim];
217  }
218  return freq;
219  }
220 
222  {
223  FrequencyValueType w2(0);
224  FrequencyType w( this->GetFrequency() );
225 
226  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
227  {
228  w2 += w[dim] * w[dim];
229  }
230  return w2;
231  }
232 
242  itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
243 
245  itkGetConstReferenceMacro(MinIndex, IndexType);
246 
248  itkGetConstReferenceMacro(MaxIndex, IndexType);
249 
251  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
252 
259  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
260 
263  void SetActualXDimensionIsOdd(bool value)
264  {
265  this->m_ActualXDimensionIsOdd = value;
266  };
267  itkGetMacro(ActualXDimensionIsOdd, bool);
268  itkBooleanMacro(ActualXDimensionIsOdd);
270 
271 private:
275  void Init()
276  {
277  SizeType sizeImage =
278  this->m_Image->GetLargestPossibleRegion().GetSize();
279  this->m_MinIndex =
280  this->m_Image->GetLargestPossibleRegion().GetIndex();
281  this->m_MaxIndex =
282  this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
283  for (unsigned int dim = 0; dim < ImageType::ImageDimension; dim++)
284  {
285  this->m_LargestPositiveFrequencyIndex[dim] = static_cast<FrequencyValueType>(
286  this->m_MinIndex[dim] + std::floor( sizeImage[dim] / 2.0 ));
287  // Set frequency metadata.
288  // Origin of frequencies is zero after a FFT.
289  this->m_FrequencyOrigin[dim] = 0.0;
290  // SamplingFrequency = 1.0 / SpatialImageSpacing
291  // Freq_BinSize = SamplingFrequency / Size
292  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
293  }
294  }
296 
303 };
304 } // end namespace itk
305 #endif
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
typename Superclass::PixelContainerPointer PixelContainerPointer
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
typename TImage::PixelContainer PixelContainer
typename Superclass::InternalPixelType InternalPixelType