aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-25 18:11:33 +0100
committerThomas White <taw@physics.org>2009-11-25 18:11:33 +0100
commit0a3ed7206e2bc009ba86a8072530a3f18196cf8f (patch)
tree6262d3e7c5ea609d9d6565638434f3e29591cc2f /src/utils.c
parent2f3f6011e2b90a54909d5f20412c179a0cb6b37e (diff)
Add Poisson noise to image
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index d5e1b874..faf78502 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -71,3 +71,25 @@ void progress_bar(int val, int total)
fflush(stdout);
}
+
+
+double poisson_noise(double expected)
+{
+ double L;
+ int k;
+ double p = 1.0;
+
+ L = exp(-expected);
+
+ do {
+
+ double r;
+
+ k++;
+ r = (double)random()/RAND_MAX;
+ p *= r;
+
+ } while ( p > L );
+
+ return k - 1;
+}