int main(int argc,char *argv[]) { int i,j,flag,n; struct image avg,max,raw; for (flag=0,i=1,n=0;i<argc;i++,n++) { printf("%d %s\n",i,argv[i]); // Read image raw=read_jpg(argv[i]); // If first image, initialize if (flag==0) { avg.nx=raw.nx; avg.ny=raw.ny; avg.nz=raw.nz; avg.z=(float *) malloc(sizeof(float)*avg.nx*avg.ny*avg.nz); for (j=0;j<avg.nx*avg.ny*avg.nz;j++) avg.z[j]=0.0; max.nx=raw.nx; max.ny=raw.ny; max.nz=raw.nz; max.z=(float *) malloc(sizeof(float)*max.nx*max.ny*max.nz); for (j=0;j<max.nx*max.ny*max.nz;j++) max.z[j]=0.0; flag=1; } // Add values for (j=0;j<avg.nx*avg.ny*avg.nz;j++) avg.z[j]+=raw.z[j]; // Add values for (j=0;j<avg.nx*avg.ny*avg.nz;j++) if (raw.z[j]>max.z[j]) max.z[j]=raw.z[j]; // Free free(raw.z); } // Average; for (j=0;j<avg.nx*avg.ny*avg.nz;j++) avg.z[j]/=(float) n; // Write write_jpg("average.jpg",avg); write_jpg("maximum.jpg",max); // Free free(avg.z); free(max.z); return 0; }
void GenericImage::load(const char* filename) { const char *ext = filename + strlen(filename) - 4; if (!strcmp(ext, ".png") || !strcmp(ext, ".PNG")) read_png(filename); else if (!strcmp(ext, ".jpg") || !strcmp(ext, ".JPG")) read_jpg(filename); // else if (!strcmp(ext, ".raw") || !strcmp(ext, ".RAW")) // read_raw(filename); else fail("only support jpeg and png image format\n"); }