hide or rename any symbols that are likely to conflict with other
[imager.git] / gaussian.c
CommitLineData
02d1d628
AMH
1#include "image.h"
2
b33c08f8 3static float
02d1d628
AMH
4gauss(int x,float std) {
5 return 1.0/(sqrt(2.0*PI)*std)*exp(-(float)(x)*(float)(x)/(2*std*std));
6}
7
8/* Counters are as follows
9 l: lines
10 i: columns
11 c: filter coeffs
12 ch: channels
13 pc: coeff equalization
14*/
15
16
17
18void
19i_gaussian(i_img *im,float stdev) {
20 int i,l,c,ch;
21 float pc;
22 float coeff[21];
23 i_color rcolor;
24 float res[11];
25 i_img timg;
26
a73aeb5f 27 mm_log((1,"i_gaussian(im %p, stdev %.2f)\n",im,stdev));
02d1d628
AMH
28
29 i_img_empty_ch(&timg,im->xsize,im->ysize,im->channels);
30
31 for(i=0;i<11;i++) coeff[10+i]=coeff[10-i]=gauss(i,stdev);
32 pc=0;
33 for(i=0;i<21;i++) pc+=coeff[i];
34 for(i=0;i<21;i++) coeff[i]/=pc;
35
36
37 for(l=0;l<im->ysize;l++) {
38 for(i=0;i<im->xsize;i++) {
39 pc=0.0;
40 for(ch=0;ch<im->channels;ch++) res[ch]=0;
41 for(c=0;c<21;c++)
42 if (i_gpix(im,i+c-10,l,&rcolor)!=-1) {
43 for(ch=0;ch<im->channels;ch++) res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
44 pc+=coeff[c];
45 }
46 for(ch=0;ch<im->channels;ch++) rcolor.channel[ch]=(unsigned char)(((res[ch]/(float)(pc)>255.0)?255.0:res[ch]/(float)(pc)));
47 i_ppix(&timg,i,l,&rcolor);
48 }
49 }
50
51 for(l=0;l<im->xsize;l++) {
52 for(i=0;i<im->ysize;i++) {
53 pc=0.0;
54 for(ch=0;ch<im->channels;ch++) res[ch]=0;
55 for(c=0;c<21;c++)
56 if (i_gpix(&timg,l,i+c-10,&rcolor)!=-1) {
57 for(ch=0;ch<im->channels;ch++) res[ch]+=(float)(rcolor.channel[ch])*coeff[c];
58 pc+=coeff[c];
59 }
60 for(ch=0;ch<im->channels;ch++) rcolor.channel[ch]=(unsigned char)(((res[ch]/(float)(pc)>255.0)?255.0:res[ch]/(float)(pc)));
61 i_ppix(im,l,i,&rcolor);
62 }
63 }
a73aeb5f 64 i_img_exorcise(&timg);
02d1d628
AMH
65}
66
67
68
69
70
71
72