ITK  5.4.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
23namespace itk
24{
119template <typename TImage>
121 : public ImageRegionConstIteratorWithIndex<TImage>
122{
123public:
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;
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 */
180 {
181 IndexType freqInd;
182 freqInd.Fill(0);
183 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
184 {
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
218 {
219 FrequencyType freq;
220 IndexType freqInd = this->GetFrequencyBin();
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);
289private:
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 }
330};
331} // end namespace itk
332#endif
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....