ITK  6.0.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 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
183 {
185 {
186 freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
187 }
188 else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
189 {
190 freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
191 }
192 }
193 return freqInd;
194 }
195
217 {
218 FrequencyType freq;
219 IndexType freqInd = this->GetFrequencyBin();
222 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
223 {
224 freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
225 }
226 return freq;
227 }
228
231 {
232 FrequencyValueType w2(0);
233 FrequencyType w(this->GetFrequency());
234
235 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
236 {
237 w2 += w[dim] * w[dim];
238 }
239 return w2;
240 }
241
251 itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
252
254 itkGetConstReferenceMacro(MinIndex, IndexType);
255
257 itkGetConstReferenceMacro(MaxIndex, IndexType);
258
260 itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
261
268 itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
269
275 void
277 {
278 this->m_ActualXDimensionIsOdd = value;
279 SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
280 auto size_estimated = 2 * (sizeImage[0] - 1);
281 size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
282 this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
283 }
284 itkGetMacro(ActualXDimensionIsOdd, bool);
285 itkBooleanMacro(ActualXDimensionIsOdd);
288private:
292 void
294 {
295 SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
296 this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
297 this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
298 for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
299 {
301 static_cast<FrequencyValueType>(this->m_MinIndex[dim] + sizeImage[dim] / 2);
302 // Set frequency metadata.
303 // Origin of frequencies is zero after a FFT.
304 this->m_FrequencyOrigin[dim] = 0.0;
305 // SamplingFrequency = 1.0 / SpatialImageSpacing
306 // Freq_BinSize = SamplingFrequency / Size
307 this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
308 }
309 // Corrections for Hermitian
310 // The fastest index has no negative frequencies.
311 this->m_LargestPositiveFrequencyIndex[0] = static_cast<FrequencyValueType>(this->m_MaxIndex[0]);
312 // In fastest dimension only:
313 // Size_estimated_original = 2 * (Size_current - 1 )
314 // Where size_current is the size of the output of RealToHalfHermitianFFT
315 // Ex: Size Original = 10, Current = 6, Estimated = 10.
316 // Size Original = 11, Current = 6, Estimated = 10.
317 auto size_estimated = 2 * (sizeImage[0] - 1);
318 size_estimated += this->GetActualXDimensionIsOdd() ? 1 : 0;
319 this->m_FrequencySpacing[0] = 1.0 / (this->m_Image->GetSpacing()[0] * size_estimated);
320 }
329};
330} // end namespace itk
331#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....