#include #include #include #include #include template int ReadImage(char* fileName,SquareGrid& red,SquareGrid& green,SquareGrid& blue){ char* ext=GetFileExtension(fileName); Image32 img; if(!strcasecmp(ext,"bmp")){BMPReadImage(fileName,img);} else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")){JPEGReadImage(fileName,img);} else{ fprintf(stderr,"Unsupported image extension: %s\n",ext); delete[] ext; return 0; } delete[] ext; int w,h,r; w=img.width(); h=img.height(); r=(w>h)?w:h; red.resize(r); green.resize(r); blue.resize(r); for(int i=0;i int WriteImage(SquareGrid& red,SquareGrid& green,SquareGrid& blue,char* fileName){ if(red.resolution()!=green.resolution() || red.resolution()!=blue.resolution()){ fprintf(stderr,"Resolutions differ: red[%d] green[%d] blue[%d]\n",red.resolution(),green.resolution(),blue.resolution()); return 0; } Image32 img; int r=red.resolution(); img.setSize(r,r); for(int i=0;i1){r=1;} if(g<0){g=0;} if(g>1){g=1;} if(b<0){b=0;} if(b>1){b=1;} p.r=(unsigned char)(r*255.0); p.g=(unsigned char)(g*255.0); p.b=(unsigned char)(b*255.0); img(i,j)=p; } } char* ext=GetFileExtension(fileName); if(!strcasecmp(ext,"bmp")){BMPWriteImage(img,fileName);} else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")){JPEGWriteImage(img,fileName);} else{ fprintf(stderr,"Unsupported image extension: %s\n",ext); delete[] ext; return 0; } delete[] ext; return 1; } int main(int argc,char* argv[]){ // Read the parameters in from the command line cmdLineString In,Out; cmdLineFloat Smooth,DLaplacian,Sharpen; cmdLineReadable Gradient,CLaplacian; char* paramNames[]={"in","out","smooth","gradient","cLaplacian","dLaplacian","sharpen"}; cmdLineReadable* params[]={&In,&Out,&Smooth,&Gradient,&CLaplacian,&DLaplacian,&Sharpen}; cmdLineParse(argc-1,&argv[1],paramNames,sizeof(paramNames)/sizeof(char*),params); if(!In.set){ fprintf(stderr,"You must specify an input file\n"); return EXIT_FAILURE; } if(!Out.set){ fprintf(stderr,"You must specify an output file\n"); return EXIT_FAILURE; } SquareGrid<> red,green,blue; FourierKey2D<> rKey,gKey,bKey; FourierTransform<> xForm; // Read in the red, green, and blue components of the image and get the Fourier coefficients if(!ReadImage(In.value,red,green,blue)){return EXIT_FAILURE;} xForm.ForwardFourier(red,rKey); xForm.ForwardFourier(green,gKey); xForm.ForwardFourier(blue,bKey); if(Smooth.set){ float sDeviation=Smooth.value; // Do the Gaussian smoothing here // ... } if(Gradient.set){ // Do the boundary detection using the magnitude of the gradient here // ... } if(CLaplacian.set){ // Do the boundary detection using the (continuous) Laplacian here // ... } if(DLaplacian.set){ float sDeviation=DLaplacian.value; // Do the boundary detection using the (discrete) Laplacian here by subtracting // the original pixel values from the smoothed pixel values // ... } if(Sharpen.set){ float sDeviation=Sharpen.value; // Do the Gaussian sharpening here // ... } // Get the image back from the Fourier coefficients, normalize, and write the image out xForm.InverseFourier(rKey,red); xForm.InverseFourier(gKey,green); xForm.InverseFourier(bKey,blue); int res=red.resolution(); for(int i=0;i