STIR 6.4.0
ScatterEstimation.h
Go to the documentation of this file.
1
2#ifndef __stir_scatter_ScatterEstimation_H__
3#define __stir_scatter_ScatterEstimation_H__
4
5/*
6 Copyright (C) 2018 - 2019 University of Hull
7 Copyright (C) 2016,2020 University College London
8 Copyright (C) 2022 National Physical Laboratory
9
10 This file is part of STIR.
11
12 SPDX-License-Identifier: Apache-2.0
13
14 See STIR/LICENSE.txt for details
15*/
26
28#include "stir/ProjData.h"
29#include "stir/ParsingObject.h"
33
35
39
40#include "stir/stir_math.h"
41#include "stir/FilePath.h"
43
44START_NAMESPACE_STIR
45
46template <class TargetT>
47class PostFiltering;
49
52{
53 float min_threshold;
55 std::string filter_filename;
57 shared_ptr<PostFiltering<DiscretisedDensity<3, float>>> filter_sptr;
58};
59
85
86class ScatterEstimation : public ParsingObject
87{
88public:
90
99 static void upsample_and_fit_scatter_estimate(ProjData& scaled_scatter_proj_data,
100 const ProjData& emission_proj_data,
101 const ProjData& scatter_proj_data,
102 BinNormalisation& scatter_normalisation,
103 const ProjData& weights_proj_data,
104 const float min_scale_factor,
105 const float max_scale_factor,
106 const unsigned half_filter_width,
107 BSpline::BSplineType spline_type = BSpline::BSplineType::linear,
108 const bool remove_interleaving = true);
109
113 explicit ScatterEstimation(const std::string& parameter_filename);
114
116 virtual Succeeded process_data();
117
119 shared_ptr<ProjData> get_output() const;
120
122 shared_ptr<ProjData> make_2D_projdata_sptr(const shared_ptr<ProjData> in_3d_sptr);
123 shared_ptr<ProjData>
124 make_2D_projdata_sptr(const shared_ptr<ProjData> in_3d_sptr, string template_filename, const bool do_normalisation = false);
125
140 virtual Succeeded set_up();
141
142 // Set functions
144 inline void set_input_proj_data_sptr(const shared_ptr<ProjData>);
146
147#if STIR_VERSION < 050000
148 void set_input_data(const shared_ptr<ProjData>& data);
149#else
150 void set_input_data(const shared_ptr<ExamData>& data);
151#endif
152 shared_ptr<const ProjData> get_input_data() const;
153
157 inline void set_attenuation_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
159 void set_attenuation_correction_proj_data_sptr(const shared_ptr<ProjData>);
161 void set_normalisation_sptr(const shared_ptr<BinNormalisation>);
163 inline void set_background_proj_data_sptr(const shared_ptr<ProjData>);
165 inline void set_initial_activity_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
166
167 inline void set_mask_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
169
170 inline void set_mask_proj_data_sptr(const shared_ptr<ProjData> arg);
171
172 void set_recompute_mask_image(bool arg);
173 void set_recompute_mask_projdata(bool arg);
174
176 void set_forward_projector_for_mask_sptr(const shared_ptr<ForwardProjectorByBin> projector_sptr);
178 shared_ptr<ForwardProjectorByBin> get_forward_projector_for_mask_sptr() const;
179
180 inline void set_scatter_simulation_method_sptr(const shared_ptr<ScatterSimulation>);
181
182 inline void set_num_iterations(int);
183
184 inline unsigned int get_half_filter_width() const;
185 inline void set_half_filter_width(unsigned int);
186
187 inline void
188 set_downsample_scanner(bool downsample_scanner, int downsampled_number_of_rings = -1, int downsampled_detectors_per_ring = -1);
189
190 void set_output_scatter_estimate_prefix(const std::string&);
191 void set_export_scatter_estimates_of_each_iteration(bool);
192
193 void set_max_scale_value(float value);
194 void set_min_scale_value(float value);
195 void set_mask_projdata_filename(std::string name);
196 void set_mask_image_filename(std::string name);
197 void set_output_additive_estimate_prefix(std::string name);
198 void set_run_debug_mode(bool debug);
199 void set_restart_reconstruction_every_scatter_iteration(bool setting);
200 bool get_restart_reconstruction_every_scatter_iteration() const;
201
203 // inline void set_zoom_xy(float);
205 // inline void set_zoom_z(float);
206
207 // Get functions
209
210 int get_iterations_num() const;
211
213 int get_num_iterations() const;
214
216 shared_ptr<const DiscretisedDensity<3, float>> get_estimated_activity_image_sptr() const;
217
219 virtual bool already_setup() const;
220
221protected:
223 void set_defaults() override;
224 void initialise_keymap() override;
225 bool post_processing() override;
226
238
243 shared_ptr<Reconstruction<DiscretisedDensity<3, float>>> reconstruction_template_sptr;
245 shared_ptr<DiscretisedDensity<3, float>> current_activity_image_sptr;
247 shared_ptr<const DiscretisedDensity<3, float>> atten_image_sptr;
249 shared_ptr<BinNormalisation> norm_3d_sptr;
251 shared_ptr<ProjData> mask_projdata_sptr;
254 shared_ptr<ProjData> input_projdata_sptr;
256 shared_ptr<ProjData> input_projdata_2d_sptr;
258 shared_ptr<ProjData> add_projdata_2d_sptr;
260 shared_ptr<ProjData> data_to_fit_projdata_sptr;
261
262 shared_ptr<ProjData> add_projdata_sptr;
264 shared_ptr<ProjData> back_projdata_2d_sptr;
266 shared_ptr<ProjData> back_projdata_sptr;
274
286 shared_ptr<ForwardProjectorByBin> forward_projector_for_mask_sptr;
287
289
306
307 std::string output_additive_estimate_prefix;
308
311
312private:
314 shared_ptr<BinNormalisation> atten_norm_3d_sptr;
315
317
318 shared_ptr<BinNormalisation> multiplicative_binnorm_2d_sptr;
319
321
322 shared_ptr<BinNormalisation> multiplicative_binnorm_sptr;
323
325 shared_ptr<ProjData> scatter_estimate_sptr;
326
328 shared_ptr<const DiscretisedDensity<3, float>> mask_image_sptr;
329
331 Succeeded set_up_iterative(shared_ptr<IterativeReconstruction<DiscretisedDensity<3, float>>> arg);
332
334 Succeeded set_up_analytic();
335
337 Succeeded project_mask_image();
338
340
341 void reconstruct_iterative(int scat_iter);
342
344
345 void reconstruct_analytic(int scat_iter);
346
348 static void apply_mask_in_place(DiscretisedDensity<3, float>&, const MaskingParameters&);
349
350 void add_proj_data(ProjData&, const ProjData&);
351
352 void subtract_proj_data(ProjData&, const ProjData&);
353
354 void apply_to_proj_data(ProjData&, const pow_times_add&);
355
357 void create_multiplicative_binnorm_sptr();
358
360 shared_ptr<BinNormalisation> get_normalisation_object_sptr(const shared_ptr<BinNormalisation>& combined_norm_sptr) const;
361
363 shared_ptr<ProjData> get_attenuation_correction_factors_sptr(const shared_ptr<BinNormalisation>& combined_norm_sptr) const;
364
367 shared_ptr<ProjData> create_new_proj_data(const std::string& filename,
368 const shared_ptr<const ExamInfo> exam_info_sptr,
369 const shared_ptr<const ProjDataInfo> proj_data_info_sptr) const;
370
372 bool do_average_at_2;
374 bool remove_interleaving;
376 bool export_scatter_estimates_of_each_iteration;
378 bool run_in_2d_projdata;
381 bool override_density_image;
383 bool override_scanner_template;
385 bool run_debug_mode;
388 std::string scatter_sim_par_filename;
390 shared_ptr<ScatterSimulation> scatter_simulation_sptr;
392 FilePath extras_path;
393
395 float max_scale_value;
397 float min_scale_value;
398
399 bool downsample_scanner_bool;
400 int downsampled_number_of_rings;
401 int downsampled_detectors_per_ring;
402
404 unsigned int half_filter_width;
405
407 bool iterative_method;
408};
409
410END_NAMESPACE_STIR
411#include "stir/scatter/ScatterEstimation.inl"
412#endif
declares the stir::AnalyticReconstruction class
Implementation of the basic components and declarations for B-Splines Interpolation.
defines the stir::CartesianCoordinate3D<coordT> class
defines the stir::DiscretisedDensity class
Declaration of class stir::FilePath This is a class implementing basic filesytem functionality....
Base class for forward projectors which work on 'large' collections of bins: given the whole image,...
Declaration of class stir::GeneralisedObjectiveFunction.
declares the stir::IterativeReconstruction class
Declaration of class stir::ParsingObject.
Declaration of class stir::ProjData.
declares the stir::Reconstruction class
Definition of class stir::ScatterSimulation.
Abstract base class for implementing bin-wise normalisation of data.
Definition BinNormalisation.h:52
This abstract class is the basis for all image representations.
Definition DiscretisedDensity.h:99
The FilePath class.
Definition FilePath.h:46
base class for iterative reconstruction objects
Definition IterativeReconstruction.h:82
The (abstract) base class for the projection data.
Definition ProjData.h:105
base class for all ReconstructionsAs there is not a lot of commonality between different reconstructi...
Definition Reconstruction.h:70
shared_ptr< ForwardProjectorByBin > get_forward_projector_for_mask_sptr() const
Get the forward projector used for the scatter estimation mask calculation.
Definition ScatterEstimation.cxx:466
shared_ptr< const DiscretisedDensity< 3, float > > atten_image_sptr
Image with attenuation values.
Definition ScatterEstimation.h:247
void set_input_data(const shared_ptr< ProjData > &data)
Set the input projdata.
Definition ScatterEstimation.cxx:342
MaskingParameters masking_parameters
Definition ScatterEstimation.h:300
shared_ptr< const DiscretisedDensity< 3, float > > get_estimated_activity_image_sptr() const
Get the (low resolution) estimate of the activity image.
Definition ScatterEstimation.cxx:366
std::string recon_template_par_filename
The filename for the parameters file of the reconstruction method.
Definition ScatterEstimation.h:281
bool restart_reconstruction_every_scatter_iteration
If set to true, the activity image will be reset to 1 in each iteration of the scatter estimation....
Definition ScatterEstimation.h:237
void set_defaults() override
All recomputes_** will default true.
Definition ScatterEstimation.cxx:59
void set_input_proj_data_sptr(const shared_ptr< ProjData >)
Set the input projdata.
Definition ScatterEstimation.inl:6
virtual Succeeded process_data()
Full process_data which performs set_up() before beginning.
Definition ScatterEstimation.cxx:852
bool recompute_mask_image
Recompute or load the mask image.
Definition ScatterEstimation.h:228
shared_ptr< ProjData > data_to_fit_projdata_sptr
Prompts - randoms.
Definition ScatterEstimation.h:260
shared_ptr< ProjData > add_projdata_2d_sptr
Additive projection data after SSRB – Randoms.
Definition ScatterEstimation.h:258
shared_ptr< ForwardProjectorByBin > forward_projector_for_mask_sptr
ForwardProjector.
Definition ScatterEstimation.h:286
virtual Succeeded set_up()
set_up
Definition ScatterEstimation.cxx:478
shared_ptr< ProjData > mask_projdata_sptr
Mask proj_data.
Definition ScatterEstimation.h:251
int get_num_iterations() const
Get the number of iterations for the scatter estimation.
Definition ScatterEstimation.cxx:1349
std::string input_projdata_filename
Filename of the measured emission 3D data.
Definition ScatterEstimation.h:277
bool _already_setup
variable to check if we have called set_up()
Definition ScatterEstimation.h:310
void set_attenuation_correction_proj_data_sptr(const shared_ptr< ProjData >)
set projection data that contains the attenuation correction factors
Definition ScatterEstimation.cxx:432
std::string atten_coeff_filename
The file name for the attenuation coefficients. If they are to be recalculated they will be stored he...
Definition ScatterEstimation.h:284
shared_ptr< DiscretisedDensity< 3, float > > current_activity_image_sptr
The current activity estimate.
Definition ScatterEstimation.h:245
shared_ptr< BinNormalisation > norm_3d_sptr
normalisation components in 3D (without atten)
Definition ScatterEstimation.h:249
int get_iterations_num() const
Set the zoom factor in the XY plane for the downsampling of the activity and attenuation image.
Definition ScatterEstimation.cxx:1356
std::string output_scatter_estimate_prefix
Output file name prefix.
Definition ScatterEstimation.h:305
shared_ptr< ProjData > back_projdata_sptr
Initially this points to the un-normalised randoms.
Definition ScatterEstimation.h:266
ScatterEstimation()
Default constructor (calls set_defaults())
Definition ScatterEstimation.cxx:155
void set_mask_proj_data_sptr(const shared_ptr< ProjData > arg)
set mask for tail-fitting
Definition ScatterEstimation.inl:49
void initialise_keymap() override
Initialise all keywords.
Definition ScatterEstimation.cxx:98
shared_ptr< ProjData > input_projdata_2d_sptr
The 2D projdata are used for the scatter estimation.
Definition ScatterEstimation.h:256
void set_forward_projector_for_mask_sptr(const shared_ptr< ForwardProjectorByBin > projector_sptr)
Sets the forward projector for the scatter estimation.
Definition ScatterEstimation.cxx:460
shared_ptr< ProjData > make_2D_projdata_sptr(const shared_ptr< ProjData > in_3d_sptr)
make projdata 2D shared pointer
Definition ScatterEstimation.cxx:170
shared_ptr< ProjData > get_output() const
Get current scatter estimate.
Definition ScatterEstimation.cxx:335
shared_ptr< Reconstruction< DiscretisedDensity< 3, float > > > reconstruction_template_sptr
This is the reconstruction object which is going to be used for the scatter estimation and the calcul...
Definition ScatterEstimation.h:243
virtual bool already_setup() const
allows checking if we have called set_up()
Definition ScatterEstimation.cxx:472
std::string atten_image_filename
This is the image file name with the anatomic information.
Definition ScatterEstimation.h:279
std::string mask_projdata_filename
Filename of mask's projdata.
Definition ScatterEstimation.h:270
void set_normalisation_sptr(const shared_ptr< BinNormalisation >)
set normalisation object (excluding attenuation)
Definition ScatterEstimation.cxx:440
void set_attenuation_image_sptr(const shared_ptr< const DiscretisedDensity< 3, float > >)
Set the full resolution attenuation image.
Definition ScatterEstimation.inl:20
std::string back_projdata_filename
Filename of background projdata.
Definition ScatterEstimation.h:272
shared_ptr< ProjData > back_projdata_2d_sptr
(Additive + Scatter Estimate) * Mult in 2D
Definition ScatterEstimation.h:264
int num_scatter_iterations
Definition ScatterEstimation.h:303
std::string mask_image_filename
Filename of mask image.
Definition ScatterEstimation.h:268
static void upsample_and_fit_scatter_estimate(ProjData &scaled_scatter_proj_data, const ProjData &emission_proj_data, const ProjData &scatter_proj_data, BinNormalisation &scatter_normalisation, const ProjData &weights_proj_data, const float min_scale_factor, const float max_scale_factor, const unsigned half_filter_width, BSpline::BSplineType spline_type=BSpline::BSplineType::linear, const bool remove_interleaving=true)
upsample coarse scatter estimate and fit it to tails of the emission data
Definition upsample_and_fit_scatter_estimate.cxx:46
shared_ptr< ProjData > input_projdata_sptr
The full 3D projdata are used for the calculation of the 2D and later for the upsampling back to 3D.
Definition ScatterEstimation.h:254
bool post_processing() override
This will be called at the end of the parsing.
Definition ScatterEstimation.cxx:224
bool recompute_mask_projdata
If set the mask projdata will be recomputed.
Definition ScatterEstimation.h:230
std::string tail_mask_par_filename
Optional parameter file for the tail fitting.
Definition ScatterEstimation.h:275
bool recompute_atten_projdata
If set to 1 the attenuation coefficients are going to be recalculated.
Definition ScatterEstimation.h:233
void set_reconstruction_method_sptr(const shared_ptr< Reconstruction< DiscretisedDensity< 3, float > > >)
Set the reconstruction method for the scatter estimation.
Definition ScatterEstimation.inl:13
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
BSplineType
enum providing constants to define the type of B-Spline used for interpolation
Definition BSplines.h:38
A struct to hold the parameters for image masking.
Definition ScatterEstimation.h:52
std::string filter_filename
filter parameter file to be used in mask calculation
Definition ScatterEstimation.h:55
shared_ptr< PostFiltering< DiscretisedDensity< 3, float > > > filter_sptr
filter to apply before thresholding
Definition ScatterEstimation.h:57