STIR  6.2.0
GeneralisedPoissonNoiseGenerator.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017, University College London
3  This file is part of STIR.
4 
5  SPDX-License-Identifier: Apache-2.0
6 
7  See STIR/LICENSE.txt for details
8 */
9 
17 #include "stir/ProjData.h"
18 
19 #include <boost/random/mersenne_twister.hpp>
20 #include <boost/random/variate_generator.hpp>
21 #include <algorithm>
22 #include <functional>
23 // boost::serialization::make_array was moved in boost 1.64
24 #if BOOST_VERSION == 106400
25 # include <boost/serialization/array_wrapper.hpp>
26 #endif
27 
28 START_NAMESPACE_STIR
29 
44 {
45  // try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
46  typedef boost::mt19937 base_generator_type;
47  typedef base_generator_type::result_type poisson_result_type;
48 
49 public:
51  GeneralisedPoissonNoiseGenerator(const float scaling_factor = 1.0F, const bool preserve_mean = false);
52 
54  void seed(unsigned int);
55 
57  float generate_random(const float mu);
58 
59  template <int num_dimensions, class elemTout, class elemTin>
60  void generate_random(Array<num_dimensions, elemTout>& array_out, const Array<num_dimensions, elemTin>& array_in)
61  {
62  std::transform(array_in.begin_all(),
63  array_in.end_all(),
64  array_out.begin_all(),
65  std::bind(generate_scaled_poisson_random, std::placeholders::_1, this->scaling_factor, this->preserve_mean));
66  }
67 
68  void generate_random(ProjData& output_projdata, const ProjData& input_projdata);
69 
70 private:
71  static base_generator_type generator;
72  const float scaling_factor;
73  const bool preserve_mean;
74 
75  static unsigned int generate_poisson_random(const float mu);
76  static float generate_scaled_poisson_random(const float mu, const float scaling_factor, const bool preserve_mean);
77 };
78 
79 END_NAMESPACE_STIR
full_iterator end_all()
end value for iterating through all elements in the array, see full_iterator
Definition: Array.inl:162
Generates noise realisations according to Poisson statistics but allowing for scaling.
Definition: GeneralisedPoissonNoiseGenerator.h:43
Declaration of class stir::ProjData.
full_iterator begin_all()
start value for iterating through all elements in the array, see full_iterator
Definition: Array.inl:190
This class defines multi-dimensional (numeric) arrays.
Definition: Array.h:73
The (abstract) base class for the projection data.
Definition: ProjData.h:103