#include #include #include #include #include #define PI 3.1415926535897932384 double ArcTan2(double y,double x){ /* This first case should never happen */ if(y==0 && x==0){return 0;} if(x==0){ if(y>0){return PI/2.0;} else{return -PI/2.0;} } if(x>=0){return atan(y/x);} else{ if(y>=0){return atan(y/x)+PI;} else{return atan(y/x)-PI;} } } 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 WriteCircularFunction(const CircularArray& values,const int& res,char* fileName){ Image32 img; img.setSize(res,res); Real c=Real(res)/2; for(int i=0;i int WriteHistogram(const CircularArray& values,const int& res,char* fileName){ Image32 img; img.setSize(res,res); Real c=Real(res)/2; for(int i=0;i\n"); fprintf(stderr,"\t--out \n"); fprintf(stderr,"\t[--rotations ]\n"); return EXIT_FAILURE; } SquareGrid<> red,green,blue; // Read in the image and set the resolution ReadImage(In.value,red,green,blue); int res=red.resolution(); if(Rotations.set && Rotations.value>0){ // Set the size of the output array equal to the maximum value // of k for which the k-fold symmetry will be computed. CircularArray<> out; out.resize(Rotations.value); // Set the k-th entry of the array "out" equal to the normalized // measure of k-fold symmetry (i.e. the value in the k-th entry // should alway be in the range [0,1], and it should be equal to // 1 if and only if the image has full k-fold symmetric. // ... // Write the histogram of rotational symmetry values out as an image WriteHistogram(out,res,Out.value); } else{ // Set the size of the output array equal to the resolution (this // will be the number of lines about which reflective symmetry will // be computed). CircularArray<> out; out.resize(res); // Set the k-th entry of the array "out" equal to the normalized // measure of reflective symmetry about the line with angle 2*PI*k/res // (i.e. the value in the k-th entry should alway be in the range [0,1], // and it should be equal to 1 if and only if the image is fully reflectively // symmetric about the line with angle 2*PI*k/res. // ... // Write the circular array of reflective symmetry values out as an image WriteCircularFunction(out,res,Out.value); } return EXIT_SUCCESS; }