STIR  6.2.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 */
28 #include "stir/ProjData.h"
29 #include "stir/ParsingObject.h"
30 #include "stir/numerics/BSplines.h"
33 
35 
39 
40 #include "stir/stir_math.h"
41 #include "stir/FilePath.h"
42 
43 START_NAMESPACE_STIR
44 
45 template <class TargetT>
46 class PostFiltering;
47 class BinNormalisation;
48 
51 {
52  float min_threshold;
54  std::string filter_filename;
56  shared_ptr<PostFiltering<DiscretisedDensity<3, float>>> filter_sptr;
57 };
58 
86 {
87 public:
89 
98  static void upsample_and_fit_scatter_estimate(ProjData& scaled_scatter_proj_data,
99  const ProjData& emission_proj_data,
100  const ProjData& scatter_proj_data,
101  BinNormalisation& scatter_normalisation,
102  const ProjData& weights_proj_data,
103  const float min_scale_factor,
104  const float max_scale_factor,
105  const unsigned half_filter_width,
106  BSpline::BSplineType spline_type = BSpline::BSplineType::linear,
107  const bool remove_interleaving = true);
108 
112  explicit ScatterEstimation(const std::string& parameter_filename);
113 
115  virtual Succeeded process_data();
116 
118  shared_ptr<ProjData> get_output() const;
119 
121  shared_ptr<ProjData> make_2D_projdata_sptr(const shared_ptr<ProjData> in_3d_sptr);
122  shared_ptr<ProjData> make_2D_projdata_sptr(const shared_ptr<ProjData> in_3d_sptr, string template_filename);
123 
138  virtual Succeeded set_up();
139 
140  // Set functions
142  inline void set_input_proj_data_sptr(const shared_ptr<ProjData>);
144 
145 #if STIR_VERSION < 050000
146  void set_input_data(const shared_ptr<ProjData>& data);
147 #else
148  void set_input_data(const shared_ptr<ExamData>& data);
149 #endif
150  shared_ptr<const ProjData> get_input_data() const;
151 
153  inline void set_reconstruction_method_sptr(const shared_ptr<Reconstruction<DiscretisedDensity<3, float>>>);
155  inline void set_attenuation_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
157  void set_attenuation_correction_proj_data_sptr(const shared_ptr<ProjData>);
159  void set_normalisation_sptr(const shared_ptr<BinNormalisation>);
161  inline void set_background_proj_data_sptr(const shared_ptr<ProjData>);
163  inline void set_initial_activity_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
164 
165  inline void set_mask_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
167 
168  inline void set_mask_proj_data_sptr(const shared_ptr<ProjData> arg);
169 
170  void set_recompute_mask_image(bool arg);
171  void set_recompute_mask_projdata(bool arg);
172 
173  inline void set_scatter_simulation_method_sptr(const shared_ptr<ScatterSimulation>);
174 
175  inline void set_num_iterations(int);
176 
177  void set_output_scatter_estimate_prefix(const std::string&);
178  void set_export_scatter_estimates_of_each_iteration(bool);
179 
180  void set_max_scale_value(float value);
181  void set_min_scale_value(float value);
182  void set_mask_projdata_filename(std::string name);
183  void set_mask_image_filename(std::string name);
184  void set_output_additive_estimate_prefix(std::string name);
185  void set_run_debug_mode(bool debug);
186  void set_restart_reconstruction_every_scatter_iteration(bool setting);
187  bool get_restart_reconstruction_every_scatter_iteration() const;
188 
190  // inline void set_zoom_xy(float);
192  // inline void set_zoom_z(float);
193 
194  // Get functions
196 
197  int get_iterations_num() const;
198 
200  int get_num_iterations() const;
201 
203  shared_ptr<const DiscretisedDensity<3, float>> get_estimated_activity_image_sptr() const;
204 
206  virtual bool already_setup() const;
207 
208 protected:
210  void set_defaults() override;
211  void initialise_keymap() override;
212  bool post_processing() override;
213 
225 
230  shared_ptr<Reconstruction<DiscretisedDensity<3, float>>> reconstruction_template_sptr;
232  shared_ptr<DiscretisedDensity<3, float>> current_activity_image_sptr;
234  shared_ptr<const DiscretisedDensity<3, float>> atten_image_sptr;
236  shared_ptr<BinNormalisation> norm_3d_sptr;
238  shared_ptr<ProjData> mask_projdata_sptr;
241  shared_ptr<ProjData> input_projdata_sptr;
243  shared_ptr<ProjData> input_projdata_2d_sptr;
245  shared_ptr<ProjData> add_projdata_2d_sptr;
247  shared_ptr<ProjData> data_to_fit_projdata_sptr;
248 
249  shared_ptr<ProjData> add_projdata_sptr;
251  shared_ptr<ProjData> back_projdata_2d_sptr;
253  shared_ptr<ProjData> back_projdata_sptr;
255  std::string mask_image_filename;
261 
266  std::string atten_image_filename;
271  std::string atten_coeff_filename;
272 
274 
291 
292  std::string output_additive_estimate_prefix;
293 
296 
297 private:
299  shared_ptr<BinNormalisation> atten_norm_3d_sptr;
300 
302 
303  shared_ptr<BinNormalisation> multiplicative_binnorm_2d_sptr;
304 
306 
307  shared_ptr<BinNormalisation> multiplicative_binnorm_sptr;
308 
310  shared_ptr<ProjData> scatter_estimate_sptr;
311 
313  shared_ptr<const DiscretisedDensity<3, float>> mask_image_sptr;
314 
316  Succeeded set_up_iterative(shared_ptr<IterativeReconstruction<DiscretisedDensity<3, float>>> arg);
317 
319  Succeeded set_up_analytic();
320 
322  Succeeded project_mask_image();
323 
325 
326  void reconstruct_iterative(int scat_iter);
327 
329 
330  void reconstruct_analytic(int scat_iter);
331 
333  static void apply_mask_in_place(DiscretisedDensity<3, float>&, const MaskingParameters&);
334 
335  void add_proj_data(ProjData&, const ProjData&);
336 
337  void subtract_proj_data(ProjData&, const ProjData&);
338 
339  void apply_to_proj_data(ProjData&, const pow_times_add&);
340 
342  void create_multiplicative_binnorm_sptr();
343 
345  shared_ptr<BinNormalisation> get_normalisation_object_sptr(const shared_ptr<BinNormalisation>& combined_norm_sptr) const;
346 
348  shared_ptr<ProjData> get_attenuation_correction_factors_sptr(const shared_ptr<BinNormalisation>& combined_norm_sptr) const;
349 
352  shared_ptr<ProjData> create_new_proj_data(const std::string& filename,
353  const shared_ptr<const ExamInfo> exam_info_sptr,
354  const shared_ptr<const ProjDataInfo> proj_data_info_sptr) const;
355 
357  bool do_average_at_2;
359  bool remove_interleaving;
361  bool export_scatter_estimates_of_each_iteration;
363  bool run_in_2d_projdata;
366  bool override_density_image;
368  bool override_scanner_template;
370  bool run_debug_mode;
373  std::string scatter_sim_par_filename;
375  shared_ptr<ScatterSimulation> scatter_simulation_sptr;
377  FilePath extras_path;
378 
380  float max_scale_value;
382  float min_scale_value;
383 
384  bool downsample_scanner_bool;
386  unsigned int half_filter_width;
387 
389  bool iterative_method;
390 };
391 
392 END_NAMESPACE_STIR
393 #include "stir/scatter/ScatterEstimation.inl"
394 #endif
std::string output_scatter_estimate_prefix
Output file name prefix.
Definition: ScatterEstimation.h:290
A struct to hold the parameters for image masking.
Definition: ScatterEstimation.h:50
The FilePath class.
Definition: FilePath.h:45
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:271
std::string filter_filename
filter parameter file to be used in mask calculation
Definition: ScatterEstimation.h:54
std::string input_projdata_filename
Filename of the measured emission 3D data.
Definition: ScatterEstimation.h:264
BSplineType
enum providing constants to define the type of B-Spline used for interpolation
Definition: BSplines.h:37
declares the stir::Reconstruction class
std::string tail_mask_par_filename
Optional parameter file for the tail fitting.
Definition: ScatterEstimation.h:262
std::string recon_template_par_filename
The filename for the parameters file of the reconstruction method.
Definition: ScatterEstimation.h:268
int num_scatter_iterations
Definition: ScatterEstimation.h:288
shared_ptr< ProjData > input_projdata_2d_sptr
The 2D projdata are used for the scatter estimation.
Definition: ScatterEstimation.h:243
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:224
shared_ptr< DiscretisedDensity< 3, float > > current_activity_image_sptr
The current activity estimate.
Definition: ScatterEstimation.h:232
A base class for objects that want to be able to parse parameter files.
Definition: ParsingObject.h:44
Declaration of class stir::ParsingObject.
shared_ptr< const DiscretisedDensity< 3, float > > atten_image_sptr
Image with attenuation values.
Definition: ScatterEstimation.h:234
shared_ptr< PostFiltering< DiscretisedDensity< 3, float > > > filter_sptr
filter to apply before thresholding
Definition: ScatterEstimation.h:56
defines the stir::DiscretisedDensity class
Declaration of class stir::ProjData.
bool recompute_mask_projdata
If set the mask projdata will be recomputed.
Definition: ScatterEstimation.h:217
bool recompute_mask_image
Recompute or load the mask image.
Definition: ScatterEstimation.h:215
shared_ptr< ProjData > mask_projdata_sptr
Mask proj_data.
Definition: ScatterEstimation.h:238
Abstract base class for implementing bin-wise normalisation of data.
Definition: BinNormalisation.h:51
std::string back_projdata_filename
Filename of background projdata.
Definition: ScatterEstimation.h:259
std::string mask_image_filename
Filename of mask image.
Definition: ScatterEstimation.h:255
std::string atten_image_filename
This is the image file name with the anatomic information.
Definition: ScatterEstimation.h:266
bool _already_setup
variable to check if we have called set_up()
Definition: ScatterEstimation.h:295
Declaration of class stir::GeneralisedObjectiveFunction.
declares the stir::AnalyticReconstruction class
base class for all ReconstructionsAs there is not a lot of commonality between different reconstructi...
Definition: Reconstruction.h:69
declares the stir::IterativeReconstruction class
Definition of class stir::ScatterSimulation.
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:230
shared_ptr< ProjData > back_projdata_sptr
Initially this points to the un-normalised randoms.
Definition: ScatterEstimation.h:253
std::string mask_projdata_filename
Filename of mask&#39;s projdata.
Definition: ScatterEstimation.h:257
Implementation of the basic components and declarations for B-Splines Interpolation.
shared_ptr< ProjData > back_projdata_2d_sptr
(Additive + Scatter Estimate) * Mult in 2D
Definition: ScatterEstimation.h:251
MaskingParameters masking_parameters
Definition: ScatterEstimation.h:285
base class for iterative reconstruction objectsThis is the base class for all iterative reconstructio...
Definition: IterativeReconstruction.h:81
Estimate the scatter probability using a model-based approach.
Definition: ScatterEstimation.h:85
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
shared_ptr< ProjData > data_to_fit_projdata_sptr
Prompts - randoms.
Definition: ScatterEstimation.h:247
defines the stir::CartesianCoordinate3D<coordT> class
double min_threshold
value to reduce the total_rpc_time values
Definition: distributed_functions.cxx:44
shared_ptr< BinNormalisation > norm_3d_sptr
normalisation components in 3D (without atten)
Definition: ScatterEstimation.h:236
The (abstract) base class for the projection data.
Definition: ProjData.h:103
shared_ptr< ProjData > add_projdata_2d_sptr
Additive projection data after SSRB – Randoms.
Definition: ScatterEstimation.h:245
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:241
Declaration of class stir::FilePath This is a class implementing basic filesytem functionality. Parts of this class were copied from Functions for filename manipulations.
bool recompute_atten_projdata
If set to 1 the attenuation coefficients are going to be recalculated.
Definition: ScatterEstimation.h:220