2 #define NB_MAX_PICS 128
15 int main(int argc, char **argv)
17 Picture *pictures[NB_MAX_PICS], *result, *ref_pic;
18 char result_name[64], ref_name[64];
20 float av, av0, te, te0, sum, sum_sq, v;
24 strcpy(result_name, "./result.ppm");
30 if(strcmp(argv[1], "-p")==0)
35 if(nb_pics == NB_MAX_PICS)
37 cerr<<"Too many pics.\n";
40 pictures[nb_pics] = new Picture;
41 cerr<<"Loading "<<argv[1]<<" ... "; cerr.flush();
42 pictures[nb_pics]->LoadPpm(argv[1]);
46 width = pictures[nb_pics]->SizeX;
47 height = pictures[nb_pics]->SizeY;
51 if((width != pictures[nb_pics]->SizeX) ||
52 (height != pictures[nb_pics]->SizeY))
54 cerr<<"Size mismatch.\n";
62 else if(strcmp(argv[1], "-o")==0)
66 strncpy(result_name, argv[2], 64);
68 cout<<"Output sent to "<<result_name<<".\n";
72 cerr<<"No filename.\n";
76 else if(strcmp(argv[1], "-r")==0)
80 strncpy(ref_name, argv[2], 64);
82 cout<<"Using "<<ref_name<<" as reference picture.\n";
86 cerr<<"No filename.\n";
92 cerr<<"Unknown option "<<argv[1]<<".\n";
97 cerr<<"Width="<<width<<" Height="<<height<<"\n";
98 cerr<<"Smoothing ... "; cerr.flush();
100 array = new float[nb_pics];
102 result = new Picture(width, height);
104 for(y=0; y<height; y++) for(x=0; x<width; x++)
107 for(k=0; k<nb_pics; k++)
108 sum += pictures[k]->GetComponent(x, y, PIC_RED);
109 for(d=0; d<PIC_DEPTH; d++)
110 result->SetComponent(x, y, d, sum/float(nb_pics));
115 if(strlen(ref_name) > 0)
117 cerr<<"Lightning correction ... "; cerr.flush();
118 ref_pic = new Picture;
119 ref_pic->LoadPpm(ref_name);
122 for(x=0; x<width; x++) for(y=0; y<height; y++)
124 v = ref_pic->GetComponent(x, y, PIC_RED);
128 av0 = sum/float(width * height);
129 te0 = sqrt(sum_sq/float(width * height) - av0*av0);
131 for(x=0; x<width; x++)
134 for(y=0; y<height; y++)
136 v = ref_pic->GetComponent(x, y, PIC_RED);
141 av = sum/float(height);
142 te = sqrt(sum_sq/float(height) - av*av);
144 for(y=0; y<height; y++)
146 v = result->GetComponent(x, y, PIC_RED);
147 //if(te>0) v = av0 + (v - av)*(te0/te);
150 if(v < 0) v = 0; else if(v > 1) v = 1;
151 for(d=0; d<PIC_DEPTH; d++) result->SetComponent(x, y, d, v);
157 else cerr<<"No column-lightning correction.\n";
159 for(k=0; k<nb_pics; k++) delete pictures[k];
161 cerr<<"Saving ... "; cerr.flush();
162 result->SavePpm(result_name);