-1

I looked out in the internet as well as I looked in here (stackoverflow) and could not find a good answer on how to implement white gaussian noise addition into my qimage object. or if there is an existing function which I can use?

any suggestions? Thx in advance

Daniel Eitan
  • 45
  • 1
  • 7
  • 1
    Did you check [this question](http://stackoverflow.com/questions/32889309/adding-gaussian-noise)? – BeyelerStudios Aug 11 '16 at 07:48
  • 1
    You labeled this with qt and qimage. May I ask what you think is different about those compared to other containers for pixel images? Are you looking explicitly for parts of qt that can do that? – Aziuth Aug 11 '16 at 08:49
  • First if there is something in qt tools that can do it that would be wonderful. Second, I have encountered solutions which in languages that I do not understand so I can not understand anything from them. – Daniel Eitan Aug 11 '16 at 11:20

1 Answers1

0

The following code helped me alot:

#include <stdlib.h>
#include <math.h>
#include <time.h>


float gauss_rand(float mean,float stdev)

{
int i;
const int ORDER=2*12; /* 12,24,36 etc. due to del^2/12 */
const double dev_norm=1.4142136; /* sqrt(ORDER/12) */
double rndno;

rndno=-(ORDER>>1);
for(i=0;i<ORDER;i++) {

    rndno+=(double)(rand()/(RAND_MAX+1.0));
}

rndno*=stdev/dev_norm;
rndno+=mean;
return((float)rndno);
}

void add_gaussian_noise(float **orig,int Ni,int Nj,float **noisy,float mean,float stdev)

{
        int i,j;
        static int kilroy=0;
    unsigned int seed;

    if(!kilroy) {
        kilroy=1;

    seed=(unsigned)time( NULL );

    // uncomment for the same noise process
//  seed=0;
    srand(seed);
}

for(i=0;i<Ni;i++)
    for(j=0;j<Nj;j++)
        noisy[i][j]=orig[i][j]+gauss_rand(mean,stdev);
}
Daniel Eitan
  • 45
  • 1
  • 7