ITK  6.0.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 * 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 itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
19#define itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex_h
20
22
23namespace itk
24{
114template <typename TImage>
116 : public ImageRegionConstIteratorWithIndex<TImage>
117{
118public:
119
123
125 using typename Superclass::IndexType;
126 using typename Superclass::SizeType;
127 using typename Superclass::OffsetType;
128 using typename Superclass::RegionType;
129 using typename Superclass::ImageType;
130 using typename Superclass::PixelContainer;
132 using typename Superclass::InternalPixelType;
133 using typename Superclass::PixelType;
134 using typename Superclass::AccessorType;
135
136 using FrequencyType = typename ImageType::SpacingType;
137 using FrequencyValueType = typename ImageType::SpacingValueType;
141 {
142 this->Init();
143 }
144
148 : ImageRegionConstIteratorWithIndex<TImage>(ptr, region)
149 {
150 this->Init();
151 }
152
161 {
162 this->Init();
163 }
164
165 /*
166 * Image Index [0, N - 1] returns [0 to N/2] (positive) union [-N/2 + 1, -1] (negative). So index N/2 + 1 returns the
167 * bin -N/2 + 1. If first index of the image is not zero, it stills returns values in the same range. f = [0, 1, ...,
168 * N/2-1, -N/2, ..., -1] if N is even f = [0, 1, ..., (N-1)/2, -(N-1)/2, ..., -1] if N is odd
169 */
172 {
173 IndexType freqInd{};
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
207 FrequencyType
209 {
210 FrequencyType freq;
211 IndexType freqInd = this->GetFrequencyBin();
214 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
215 {
216 freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
217 }
218 return freq;
219 }
220
221 FrequencyValueType
223 {
224 FrequencyValueType w2(0);
225 FrequencyType w(this->GetFrequency());
226
227 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
228 {
229 w2 += w[dim] * w[dim];
230 }
231 return w2;
232 }
233
243 itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
244
246 itkGetConstReferenceMacro(MinIndex, IndexType);
247
249 itkGetConstReferenceMacro(MaxIndex, IndexType);
250
252 itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
253
260 itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
261
264 void
266 {
267 this->m_ActualXDimensionIsOdd = value;
268 }
269 itkGetMacro(ActualXDimensionIsOdd, bool);
270 itkBooleanMacro(ActualXDimensionIsOdd);
273private:
277 void
279 {
280 SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
281 this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
282 this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
283 for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
284 {
285 this->m_LargestPositiveFrequencyIndex[dim] =
286 static_cast<FrequencyValueType>(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 }
303};
304} // end namespace itk
305#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...
typename PixelContainer::Pointer PixelContainerPointer
typename TImage::InternalPixelType InternalPixelType
typename TImage::PixelContainer PixelContainer
A multi-dimensional iterator templated over image type that walks an image region and is specialized ...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....