The flutter shutter camera simulator
standard_routines.cpp
Go to the documentation of this file.
00001 /*standard_routines.cp*/
00002 /*
00003 * Copyright 2012 IPOL Image Processing On Line http://www.ipol.im/
00004 *
00005 * This program is free software: you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License as published by
00007 * the Free Software Foundation, either version 3 of the License, or
00008 * (at your option) any later version.
00009 *
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 *
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00027 #include <math.h>
00028 #include <stdio.h>
00029 #define ABS(x)    (((x) > 0) ? (x) : (-(x))) //absolute value
00030 
00031 
00036 
00049 void image_difference(float *groundtruth,float *restored, int width, int height,
00050                       int channel_number, float *difference)
00051 {
00052 
00053     for (int i=0; i<width*height*channel_number; i++)
00054     {
00055         difference[i]=groundtruth[i]-restored[i];
00056 
00057     }
00058 
00059 }
00060 
00061 
00062 
00063 
00064 
00065 
00070 
00085 void RMSE(float *difference, int width, int height,int channel_number,int border
00086           ,int flag_rmse_ci)
00087 {
00088     float rmse=0;
00089     int num_pixels=0;
00090     for (int k=0; k<channel_number; k++)
00091         for (int j=0; j<height; j++)
00092         {
00093             for (int i=border; i<width-border; i++)
00094             {
00095                 rmse=rmse+difference[i+width*j+k*width*height]*
00096                      difference[i+width*j+k*width*height];
00097                 num_pixels++;
00098             }
00099         }
00100     rmse=sqrt(rmse/(num_pixels));
00101     float psnr = 10.0f * log10f(255.0f * 255.0f / (rmse * rmse));
00102     //std::cerr << "RMSE=" <<  std::endl;
00103     //std::cerr << rmse <<  std::endl;
00104     //std::cerr << "PSRN=" <<  std::endl;
00105     //std::cerr << psnr <<  std::endl;
00106     if (flag_rmse_ci==0)
00107     {
00108         printf("RMSE: %f\n", rmse);
00109         printf("PSNR: %f\n", psnr);
00110     }
00111     else
00112     {
00113         printf("Contrast Invariant RMSE: %f\n", rmse);
00114         printf("Contrast Invariant PSNR: %f\n", psnr);
00115     }
00116 
00117 
00118 }
00119 
00120 
00121 
00122 
00123 
00128 
00139 void dynamic_renormalization(float *image, int width, int height,
00140                              int channel_number)
00141 {
00142 
00144     float min=image[0];
00145     float max=image[0];
00146     for (int i=1; i<width*height*channel_number; i++)
00147     {
00148         if (image[i]<min) min=image[i];
00149         if (image[i]>max) max=image[i];
00150     }
00151 
00153     for (int i=1; i<width*height*channel_number; i++)
00154     {
00155         image[i]=(255*(image[i]-min)/(max-min));
00156     }
00157 }
00158 
00159 
00160 
00166 
00176 float abs_hat_alpha(const float* code, int code_length, float xi)
00177 {
00179     //initialization
00180     float re_abs_hat_alpha=0; //real part
00181     float im_abs_hat_alpha=0; //imaginary part
00182     //Main loop
00183     for (int k=0; k<code_length; k++)
00184     {
00185         im_abs_hat_alpha =im_abs_hat_alpha+code[k]*sin(-xi*(k+0.5));
00186         re_abs_hat_alpha =re_abs_hat_alpha+code[k]*cos(-xi*(k+0.5));
00187     }
00188 
00189     if (ABS(xi)>0) //avoiding 0/0
00190     {
00191         im_abs_hat_alpha =im_abs_hat_alpha*sin(xi/2)/(xi/2);//ELSE =1;
00192         re_abs_hat_alpha =re_abs_hat_alpha*sin(xi/2)/(xi/2); //ELSE =1;
00193     }
00194 
00195     return(pow(im_abs_hat_alpha*im_abs_hat_alpha+
00196                re_abs_hat_alpha*re_abs_hat_alpha,0.5));
00198 }
 All Files Functions Variables Typedefs Defines