ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSpectra1DImageFilter.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 itkSpectra1DImageFilter_h
19#define itkSpectra1DImageFilter_h
20
24
25#include "itkMacro.h"
26
27#if ITK_VERSION_MAJOR >= 6
28# include "itk_pocketfft.h"
29#else
30# include "vnl/algo/vnl_fft_base.h"
31# include "vnl/algo/vnl_fft_1d.h"
32#endif
33
34#include <utility>
35
36#include <unordered_map>
37
39
40namespace itk
41{
42
68template <typename TInputImage, typename TSupportWindowImage, typename TOutputImage>
69class ITK_TEMPLATE_EXPORT Spectra1DImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
70{
71public:
72 ITK_DISALLOW_COPY_AND_MOVE(Spectra1DImageFilter);
73
74 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
75
76 using InputImageType = TInputImage;
77 using SupportWindowImageType = TSupportWindowImage;
78 using OutputImageType = TOutputImage;
79
81
87
88 itkOverrideGetNameOfClassMacro(Spectra1DImageFilter);
89 itkNewMacro(Self);
90
95
98 itkSetInputMacro(ReferenceSpectraImage, OutputImageType);
99 itkGetInputMacro(ReferenceSpectraImage, OutputImageType);
100
101protected:
103 ~Spectra1DImageFilter() override = default;
104
105 using OutputImageRegionType = typename OutputImageType::RegionType;
106
107 void
109 void
111 void
112 ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId) override;
113 void
114 VerifyInputInformation() const override;
115
116private:
117 using ComplexType = std::complex<ScalarType>;
118 using ComplexVectorType = vnl_vector<ComplexType>;
119 using SpectraVectorType = std::vector<ScalarType>;
120 using IndexType = typename InputImageType::IndexType;
121 using SpectraLineType = std::pair<IndexType, SpectraVectorType>;
122 using SpectraLinesContainerType = std::list<SpectraLineType>;
123 using SupportWindowType = typename SupportWindowImageType::PixelType;
125#if ITK_VERSION_MAJOR >= 6
126 // exp(+i) and no normalization, matching what vnl_fft_1d::bwd_transform computed.
127 struct FFT1DType
128 {
129 explicit FFT1DType(SizeValueType length)
130 : m_Length(length)
131 {}
132
133 void
134 bwd_transform(vnl_vector<std::complex<ScalarType>> & signal) const
135 {
136 const itk::detail::pocketfft::shape_t shape{ static_cast<std::size_t>(m_Length) };
137 const itk::detail::pocketfft::stride_t stride{ static_cast<std::ptrdiff_t>(sizeof(std::complex<ScalarType>)) };
138 const itk::detail::pocketfft::shape_t axes{ 0 };
139 itk::detail::pocketfft::c2c(
140 shape, stride, stride, axes, true, signal.data_block(), signal.data_block(), ScalarType{ 1 });
141 }
142
143 private:
144 SizeValueType m_Length;
145 };
146#else
147 using FFT1DType = vnl_fft_1d<ScalarType>;
148#endif
149
152
153 using LineWindowMapType = std::unordered_map<FFT1DSizeType, SpectraVectorType>;
154
162 using PerThreadDataContainerType = std::vector<PerThreadData>;
164
165 typename OutputImageType::Pointer m_ReferenceSpectraImage;
166
167 void
168 ComputeSpectra(const IndexType & lineIndex, ThreadIdType threadId, SpectraLineType & spectraLine);
169 static void
171};
172
173} // end namespace itk
174
175#ifndef ITK_MANUAL_INSTANTIATION
176# include "itkSpectra1DImageFilter.hxx"
177#endif
178
179#endif // itkSpectra1DImageFilter_h
typename PixelType::ComponentType ComponentType
Read-only ImageRegionIterator: ImageRegionConstIterator<TImage> behaves as ImageRegionIterator<const ...
Implements transparent reference counting.
std::list< SpectraLineType > SpectraLinesContainerType
std::pair< IndexType, SpectraVectorType > SpectraLineType
typename DefaultConvertPixelTraits< typename OutputImageType::PixelType >::ComponentType ScalarType
PerThreadDataContainerType m_PerThreadDataContainer
~Spectra1DImageFilter() override=default
itkSetInputMacro(SupportWindowImage, SupportWindowImageType)
itkGetInputMacro(SupportWindowImage, SupportWindowImageType)
std::unordered_map< FFT1DSizeType, SpectraVectorType > LineWindowMapType
vnl_fft_1d< ScalarType > FFT1DType
Spectra1DSupportWindowImageFilter< InputImageType > Spectra1DSupportWindowFilterType
void VerifyInputInformation() const override
Verifies that the input images occupy the same physical space and the each index is at the same physi...
OutputImageType::Pointer m_ReferenceSpectraImage
static void AddLineWindow(FFT1DSizeType length, LineWindowMapType &lineWindowMap)
itkGetInputMacro(ReferenceSpectraImage, OutputImageType)
typename SupportWindowImageType::PixelType SupportWindowType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) override
ImageRegionConstIterator< InputImageType > InputImageIteratorType
typename InputImageType::IndexType IndexType
itkSetInputMacro(ReferenceSpectraImage, OutputImageType)
std::vector< ScalarType > SpectraVectorType
void BeforeThreadedGenerateData() override
vnl_vector< ComplexType > ComplexVectorType
std::vector< PerThreadData > PerThreadDataContainerType
ImageToImageFilter< InputImageType, OutputImageType > Superclass
void GenerateOutputInformation() override
std::complex< ScalarType > ComplexType
SmartPointer< const Self > ConstPointer
typename Spectra1DSupportWindowFilterType::FFT1DSizeType FFT1DSizeType
void ComputeSpectra(const IndexType &lineIndex, ThreadIdType threadId, SpectraLineType &spectraLine)
static constexpr unsigned int ImageDimension
TSupportWindowImage SupportWindowImageType
typename OutputImageType::RegionType OutputImageRegionType
Generate an image of local spectra computation support windows.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:82
unsigned int ThreadIdType
Definition itkIntTypes.h:98