ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex.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 itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex_h
19 #define itkFrequencyShiftedFFTLayoutImageRegionConstIteratorWithIndex_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 [-N/2 + 1, -1] (negative) union [0 to N/2] (positive). So index N/2 + 1 returns the bin 0.
165  * It is a shift by -N/2 + 1, from [0, N-1] to [-N/2 + 1, N/2]
166  * If first index of the image is not zero, it stills returns values in the same range.
167  */
169  {
170  IndexType freqInd;
171 
172  freqInd.Fill(0);
173  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
174  {
175  freqInd[dim] = this->m_PositionIndex[dim] - this->m_ZeroFrequencyIndex[dim];
176  }
177  return freqInd;
178  }
179 
194  {
195  FrequencyType freq;
196  IndexType freqInd = this->GetFrequencyBin();
198 
199  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
200  {
201  freq[dim] = this->m_FrequencyOrigin[dim]
202  + this->m_FrequencySpacing[dim] * freqInd[dim];
203  }
204  return freq;
205  }
206 
208  {
209  FrequencyValueType w2(0);
210  FrequencyType w( this->GetFrequency() );
211 
212  for (unsigned int dim = 0; dim < TImage::ImageDimension; dim++)
213  {
214  w2 += w[dim] * w[dim];
215  }
216  return w2;
217  }
218 
225  itkGetConstReferenceMacro(ZeroFrequencyIndex, IndexType);
226 
228  itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
229 
236  itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
237 
240  void SetActualXDimensionIsOdd(bool value)
241  {
242  this->m_ActualXDimensionIsOdd = value;
243  };
244  itkGetMacro(ActualXDimensionIsOdd, bool);
245  itkBooleanMacro(ActualXDimensionIsOdd);
247 
248 private:
251  void Init()
252  {
253  IndexType minIndex =
254  this->m_Image->GetLargestPossibleRegion().GetIndex();
255  SizeType sizeImage =
256  this->m_Image->GetLargestPossibleRegion().GetSize();
257  for (unsigned int dim = 0; dim < ImageType::ImageDimension; dim++)
258  {
259  this->m_ZeroFrequencyIndex[dim] = static_cast<FrequencyValueType>(
260  minIndex[dim] + std::floor( sizeImage[dim] / 2.0 ));
261  // Set frequency metadata.
262  // Origin of frequencies is zero in the standard layout of a FFT output.
263  this->m_FrequencyOrigin[dim] = 0.0;
264  // SamplingFrequency = 1.0 / SpatialImageSpacing
265  // Freq_BinSize = SamplingFrequency / Size
266  this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
267  }
268  }
270 
275 };
276 } // end namespace itk
277 #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