diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-12-13 22:56:46 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-12-13 22:56:46 +0000 |
commit | a9b2c5226124d5c0592e424991e007fe0d2db6b2 (patch) | |
tree | eafa5833c2b6222776ec7a0f3e2d279aefbdbbdf | |
parent | bf492383880c14e1a943ac3eabc73718ad7db805 (diff) | |
download | netpbm-mirror-a9b2c5226124d5c0592e424991e007fe0d2db6b2.tar.gz netpbm-mirror-a9b2c5226124d5c0592e424991e007fe0d2db6b2.tar.xz netpbm-mirror-a9b2c5226124d5c0592e424991e007fe0d2db6b2.zip |
Base Poisson noise on intensity, not brightness, to match the physical effect of quantized light
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4003 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | editor/pamaddnoise.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/editor/pamaddnoise.c b/editor/pamaddnoise.c index fa0df6f5..8035b197 100644 --- a/editor/pamaddnoise.c +++ b/editor/pamaddnoise.c @@ -31,6 +31,7 @@ #include <math.h> #include "pm_c_util.h" +#include "pm_gamma.h" #include "pam.h" static double const EPSILON = 1.0e-5; @@ -218,7 +219,9 @@ addPoissonNoise(struct pam * const pamP, -----------------------------------------------------------------------------*/ samplen const origSamplen = pnm_normalized_sample(pamP, origSample); - double const lambda = origSamplen * lambdaOfMaxval; + float const origSampleIntensity = pm_ungamma709(origSamplen); + + double const lambda = origSampleIntensity * lambdaOfMaxval; double const u = rand1(); @@ -240,7 +243,11 @@ addPoissonNoise(struct pam * const pamP, break; } - *newSampleP = pnm_unnormalized_sample(pamP, k/lambdaOfMaxval); + { + samplen const newSamplen = pm_gamma709(k/lambdaOfMaxval); + + *newSampleP = pnm_unnormalized_sample(pamP, newSamplen); + } } |