ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkFrequencyFFTLayoutImageRegionIteratorWithIndex.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 itkFrequencyFFTLayoutImageRegionIteratorWithIndex_h
19#define itkFrequencyFFTLayoutImageRegionIteratorWithIndex_h
20
22
23namespace itk
24{
114template <typename TImage>
116{
117 template <typename>
119
120public:
124
126 using typename Superclass::IndexType;
127 using typename Superclass::SizeType;
128 using typename Superclass::OffsetType;
129 using typename Superclass::RegionType;
130 using typename Superclass::ImageType;
131 using typename Superclass::PixelContainer;
133 using typename Superclass::InternalPixelType;
134 using typename Superclass::PixelType;
135 using typename Superclass::AccessorType;
136
137 using FrequencyType = typename ImageType::SpacingType;
138 using FrequencyValueType = typename ImageType::SpacingValueType;
145
149 : Superclass(ptr, region)
150 {
151 this->Init();
152 }
153
160 template <
161 typename TOtherImage,
162 std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage> && !std::is_const_v<TImage>, int> = 0>
168
170 template <
171 typename TOtherImage,
172 std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage> && std::is_const_v<TImage>, int> = 0>
178
180 template <typename TOtherImage, std::enable_if_t<detail::IsImageIteratorConvertible_v<TOtherImage, TImage>, int> = 0>
190
191 /*
192 * Image Index [0, N - 1] returns [0 to N/2] (positive) union [-N/2 + 1, -1] (negative). So index N/2 + 1 returns the
193 * bin -N/2 + 1. If first index of the image is not zero, it stills returns values in the same range. f = [0, 1, ...,
194 * N/2-1, -N/2, ..., -1] if N is even f = [0, 1, ..., (N-1)/2, -(N-1)/2, ..., -1] if N is odd
195 */
196 [[nodiscard]] IndexType
198 {
199 IndexType freqInd{};
200 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
201 {
203 {
204 freqInd[dim] = this->m_PositionIndex[dim] - this->m_MinIndex[dim];
205 }
206 else // -. From -N/2 + 1 (Nyquist if even) to -1 (-df in frequency)
207 {
208 freqInd[dim] = this->m_PositionIndex[dim] - (this->m_MaxIndex[dim] + 1);
209 }
210 }
211 return freqInd;
212 }
213
233 [[nodiscard]] FrequencyType
235 {
236 FrequencyType freq;
237 IndexType freqInd = this->GetFrequencyBin();
238
239 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
240 {
241 freq[dim] = this->m_FrequencyOrigin[dim] + this->m_FrequencySpacing[dim] * freqInd[dim];
242 }
243 return freq;
244 }
245
246 [[nodiscard]] FrequencyValueType
248 {
249 FrequencyValueType w2(0);
250 FrequencyType w(this->GetFrequency());
251
252 for (unsigned int dim = 0; dim < TImage::ImageDimension; ++dim)
253 {
254 w2 += w[dim] * w[dim];
255 }
256 return w2;
257 }
258
268 itkGetConstReferenceMacro(LargestPositiveFrequencyIndex, IndexType);
269
271 itkGetConstReferenceMacro(MinIndex, IndexType);
272
274 itkGetConstReferenceMacro(MaxIndex, IndexType);
275
277 itkGetConstReferenceMacro(FrequencyOrigin, FrequencyType);
278
285 itkGetConstReferenceMacro(FrequencySpacing, FrequencyType);
286
290 void
292 {
293 this->m_ActualXDimensionIsOdd = value;
294 }
295 itkGetMacro(ActualXDimensionIsOdd, bool);
296 itkBooleanMacro(ActualXDimensionIsOdd);
298private:
302 void
304 {
305 if (this->m_Image.IsNull())
306 {
307 return;
308 }
309 SizeType sizeImage = this->m_Image->GetLargestPossibleRegion().GetSize();
310 this->m_MinIndex = this->m_Image->GetLargestPossibleRegion().GetIndex();
311 this->m_MaxIndex = this->m_Image->GetLargestPossibleRegion().GetUpperIndex();
312 for (unsigned int dim = 0; dim < ImageType::ImageDimension; ++dim)
313 {
315 static_cast<FrequencyValueType>(this->m_MinIndex[dim] + std::floor(sizeImage[dim] / 2.0));
316 // Set frequency metadata.
317 // Origin of frequencies is zero after a FFT.
318 this->m_FrequencyOrigin[dim] = 0.0;
319 // SamplingFrequency = 1.0 / SpatialImageSpacing
320 // Freq_BinSize = SamplingFrequency / Size
321 this->m_FrequencySpacing[dim] = 1.0 / (this->m_Image->GetSpacing()[dim] * sizeImage[dim]);
322 }
323 }
324
331};
332
333// Deduction guides for class template argument deduction (CTAD).
334template <typename TImage>
337
338template <typename TImage>
341
352template <typename TImage>
370
371// Deduction guides for class template argument deduction (CTAD).
372template <typename TImage>
373FrequencyFFTLayoutImageRegionConstIteratorWithIndex(const TImage *, const typename TImage::RegionType &)
375
376template <typename TImage>
379
380template <typename TImage>
383
384} // end namespace itk
385#endif
Read-only FrequencyFFTLayoutImageRegionIteratorWithIndex: FrequencyFFTLayoutImageRegionConstIteratorW...
FrequencyFFTLayoutImageRegionIteratorWithIndex< std::add_const_t< TImage > > Superclass
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
FrequencyFFTLayoutImageRegionIteratorWithIndex(const FrequencyFFTLayoutImageRegionIteratorWithIndex< TOtherImage > &it)
FrequencyFFTLayoutImageRegionIteratorWithIndex(const ImageIteratorWithIndex< TOtherImage > &it)
A base class for multi-dimensional iterators templated over image type that are designed to efficient...
typename PixelContainer::Pointer PixelContainerPointer
detail::IteratorImageType_t< TImage > ImageType
typename TImage::AccessorType AccessorType
typename TImage::InternalPixelType InternalPixelType
typename TImage::PixelContainer PixelContainer
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
FrequencyFFTLayoutImageRegionIteratorWithIndex(SmartPointer< TImage >, const typename TImage::RegionType &) -> FrequencyFFTLayoutImageRegionIteratorWithIndex< TImage >
FrequencyFFTLayoutImageRegionConstIteratorWithIndex(const TImage *, const typename TImage::RegionType &) -> FrequencyFFTLayoutImageRegionConstIteratorWithIndex< TImage >