I'm trying to compose an fx operation where
output value = max( 0, input value + value from normal distribution with sigma)
and I see I can get a random number, but I'd rather not make some crazy expression to go from uniform [0,1] random to normal random, besides doing so might be slow in imagemagick. Is there another way?
random from a distribution using fx
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: random from a distribution using fx
why not just add Gaussian noise to your image. see +noise gaussian and -evaluate gaussian-noise (and the Box-Muller Gaussian Noise formula)
http://www.imagemagick.org/script/comma ... .php#noise
http://www.imagemagick.org/script/comma ... p#evaluate
http://www.imagemagick.org/Usage/canvas/#random
viewtopic.php?f=3&t=14863
http://en.wikipedia.org/wiki/Box–Muller_transform
http://www.imagemagick.org/script/comma ... .php#noise
http://www.imagemagick.org/script/comma ... p#evaluate
http://www.imagemagick.org/Usage/canvas/#random
viewtopic.php?f=3&t=14863
http://en.wikipedia.org/wiki/Box–Muller_transform
Re: random from a distribution using fx
What I arrived at (with linebreaks to improve readibility) is:
-fx 'iso=32;
rone=rand();
rtwo=rand();
myn=sqrt(-2*ln(rone))*cos(2*Pi*rtwo);
myntwo=sqrt(-2*ln(rtwo))*cos(2*Pi*rone);
pnoise=sqrt(p)*myn*sqrt(iso)*channel(4.28,3.86,6.68,0)/255;
max(0,p+pnoise)'
So you can see, while I needed a gaussian distribution, I'm adding noise that is proportional to the gaussian. Of course if I can rework this using image multiplication with a random image it will go more quickly (do you see an easy way to do that, I worry about the noise values being truncated if they go below zero). The Box-Muller is definitely the way to go here. What I'm doing it reproducing the noise I observe in my camera at high iso's so that I can test a few different noise removal protocols.
Or rather this was my first attempt. I now have a mix of shot noise and random noise because I feel it better approximates my noise of my sensor.
-fx 'iso=32;
rone=rand();
rtwo=rand();
myn=sqrt(-2*ln(rone))*cos(2*Pi*rtwo);
myntwo=sqrt(-2*ln(rtwo))*cos(2*Pi*rone);
pnoise=sqrt(p)*myn*sqrt(iso)*channel(4.28,3.86,6.68,0)/255;
max(0,p+pnoise)'
So you can see, while I needed a gaussian distribution, I'm adding noise that is proportional to the gaussian. Of course if I can rework this using image multiplication with a random image it will go more quickly (do you see an easy way to do that, I worry about the noise values being truncated if they go below zero). The Box-Muller is definitely the way to go here. What I'm doing it reproducing the noise I observe in my camera at high iso's so that I can test a few different noise removal protocols.
Or rather this was my first attempt. I now have a mix of shot noise and random noise because I feel it better approximates my noise of my sensor.