RTK  2.6.0
Reconstruction Toolkit
rtkSpectralForwardModelImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright RTK Consortium
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 
19 #ifndef rtkSpectralForwardModelImageFilter_h
20 #define rtkSpectralForwardModelImageFilter_h
21 
25 
27 #include <itkInPlaceImageFilter.h>
28 #include <itkCastImageFilter.h>
29 
30 namespace rtk
31 {
45 template <typename DecomposedProjectionsType,
46  typename MeasuredProjectionsType,
47  typename IncidentSpectrumImageType = itk::Image<float, 3>,
48  typename DetectorResponseImageType = itk::Image<float, 2>,
49  typename MaterialAttenuationsImageType = itk::Image<float, 2>>
50 class ITK_TEMPLATE_EXPORT SpectralForwardModelImageFilter
51  : public itk::InPlaceImageFilter<MeasuredProjectionsType, MeasuredProjectionsType>
52 {
53 public:
54  ITK_DISALLOW_COPY_AND_MOVE(SpectralForwardModelImageFilter);
55 
61 
63  using InputImageType = MeasuredProjectionsType;
64  using OutputImageType = MeasuredProjectionsType;
65 
68  using DetectorResponseType = vnl_matrix<double>;
69  using MaterialAttenuationsType = vnl_matrix<double>;
70  using DecomposedProjectionsDataType = typename DecomposedProjectionsType::PixelType::ValueType;
71  using MeasuredProjectionsDataType = typename MeasuredProjectionsType::PixelType::ValueType;
72 
73 #ifndef ITK_FUTURE_LEGACY_REMOVE
74 
75  using VectorSpectrumImageType = itk::VectorImage<float, 2>;
78 #endif
79 
81  itkNewMacro(Self);
82 
84  itkOverrideGetNameOfClassMacro(SpectralForwardModelImageFilter);
85 
87  void
88  SetInputIncidentSpectrum(const IncidentSpectrumImageType * IncidentSpectrum);
89  void
90  SetInputSecondIncidentSpectrum(const IncidentSpectrumImageType * SecondIncidentSpectrum);
91 #ifndef ITK_FUTURE_LEGACY_REMOVE
92  void
93  SetInputIncidentSpectrum(const VectorSpectrumImageType * IncidentSpectrum);
94  void
95  SetInputSecondIncidentSpectrum(const VectorSpectrumImageType * SecondIncidentSpectrum);
96 #endif
97  typename IncidentSpectrumImageType::ConstPointer
98  GetInputIncidentSpectrum();
99  typename IncidentSpectrumImageType::ConstPointer
100  GetInputSecondIncidentSpectrum();
102 
104  void
105  SetInputDecomposedProjections(
106  const typename itk::ImageBase<DecomposedProjectionsType::ImageDimension> * DecomposedProjections);
107  template <unsigned int VNumberOfMaterials>
108  void
109  SetInputFixedVectorLengthDecomposedProjections(
111  DecomposedProjectionsType::ImageDimension> * DecomposedProjections);
112  typename DecomposedProjectionsType::ConstPointer
113  GetInputDecomposedProjections();
115 
117  void
118  SetInputMeasuredProjections(
119  const typename itk::ImageBase<MeasuredProjectionsType::ImageDimension> * MeasuredProjections);
120  template <unsigned int VNumberOfSpectralBins>
121  void
122  SetInputFixedVectorLengthMeasuredProjections(
124  MeasuredProjectionsType::ImageDimension> * MeasuredProjections);
125  typename MeasuredProjectionsType::ConstPointer
126  GetInputMeasuredProjections();
128 
130  void
131  SetDetectorResponse(const DetectorResponseImageType * DetectorResponse);
132  typename DetectorResponseImageType::ConstPointer
133  GetDetectorResponse();
135 
137  void
138  SetMaterialAttenuations(const MaterialAttenuationsImageType * MaterialAttenuations);
139  typename MaterialAttenuationsImageType::ConstPointer
140  GetMaterialAttenuations();
142 
143  typename DecomposedProjectionsType::ConstPointer
144  GetOutputCramerRaoLowerBound();
145 
146  typename MeasuredProjectionsType::ConstPointer
147  GetOutputVariances();
148 
149  itkSetMacro(Thresholds, ThresholdsType);
150  itkGetMacro(Thresholds, ThresholdsType);
151 
152  itkSetMacro(NumberOfSpectralBins, unsigned int);
153  itkGetMacro(NumberOfSpectralBins, unsigned int);
154 
155  itkSetMacro(NumberOfMaterials, unsigned int);
156  itkGetMacro(NumberOfMaterials, unsigned int);
157 
158  itkSetMacro(NumberOfEnergies, unsigned int);
159  itkGetMacro(NumberOfEnergies, unsigned int);
160 
161  itkSetMacro(IsSpectralCT, bool);
162  itkGetMacro(IsSpectralCT, bool);
163 
164  itkSetMacro(ComputeVariances, bool);
165  itkGetMacro(ComputeVariances, bool);
166 
167  itkSetMacro(ComputeCramerRaoLowerBound, bool);
168  itkGetMacro(ComputeCramerRaoLowerBound, bool);
169 
170 protected:
172  ~SpectralForwardModelImageFilter() override = default;
173 
176  using Superclass::MakeOutput;
178  MakeOutput(DataObjectPointerArraySizeType idx) override;
179 
180  void
181  GenerateOutputInformation() override;
182 
183  void
184  GenerateInputRequestedRegion() override;
185 
186  void
187  BeforeThreadedGenerateData() override;
188  void
189  DynamicThreadedGenerateData(const typename OutputImageType::RegionType & outputRegionForThread) override;
190 
193  void
194  VerifyInputInformation() const override
195  {}
196 
199 
202  unsigned int m_NumberOfEnergies;
203 
205  unsigned int m_NumberOfIterations;
206  unsigned int m_NumberOfMaterials;
208  bool m_IsSpectralCT; // If not, it is dual energy CT
209  bool m_ComputeVariances; // Only implemented for dual energy CT
210  bool m_ComputeCramerRaoLowerBound; // Only implemented for spectral CT
211 
212 #ifndef ITK_FUTURE_LEGACY_REMOVE
213 
214  typename FlattenVectorFilterType::Pointer m_FlattenFilter;
215  typename FlattenVectorFilterType::Pointer m_FlattenSecondFilter;
216  typename PermuteFilterType::Pointer m_PermuteFilter;
217  typename PermuteFilterType::Pointer m_PermuteSecondFilter;
218 #endif
219 
220 }; // end of class
221 
222 // Function to bin a detector response matrix according to given energy thresholds
223 template <typename OutputElementType, typename DetectorResponseImageType, typename ThresholdsType>
224 vnl_matrix<OutputElementType>
225 SpectralBinDetectorResponse(const DetectorResponseImageType * drm,
226  const ThresholdsType & thresholds,
227  const unsigned int numberOfEnergies);
228 
229 } // end namespace rtk
230 
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 # include "rtkSpectralForwardModelImageFilter.hxx"
234 #endif
235 
236 #endif
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Forward model for the decomposition of spectral projection images into material projections.
#define itkSetMacro(name, type)
typename DecomposedProjectionsType::PixelType::ValueType DecomposedProjectionsDataType
vnl_matrix< OutputElementType > SpectralBinDetectorResponse(const DetectorResponseImageType *drm, const ThresholdsType &thresholds, const unsigned int numberOfEnergies)
Re-writes a vector image as an image.
typename MeasuredProjectionsType::PixelType::ValueType MeasuredProjectionsDataType