Fixed PSNR calculation

This commit is contained in:
Marko Viitanen 2013-04-05 16:27:18 +03:00
parent 9888eaf9a4
commit f85db78fe2
5 changed files with 20 additions and 17 deletions

View file

@ -144,11 +144,12 @@
fread(encoder->in.cur_pic.uData, cfg->width*cfg->height>>2,1,input);
fread(encoder->in.cur_pic.vData, cfg->width*cfg->height>>2,1,input);
/* Clear reconstruction buffers */
/* Clear reconstruction buffers (not needed, for debugging) */
/*
memset(encoder->in.cur_pic.yRecData, 0, cfg->width*cfg->height);
memset(encoder->in.cur_pic.uRecData, 128, cfg->width*cfg->height>>2);
memset(encoder->in.cur_pic.vRecData, 128, cfg->width*cfg->height>>2);
*/
/* /////////////THE ACTUAL CODING HAPPENDS HERE\\\\\\\\\\\\\\\\\\\ */
encode_one_frame(encoder);
@ -164,7 +165,7 @@
temp_PSNR[1] = imagePSNR(encoder->in.cur_pic.uData,encoder->in.cur_pic.uRecData,cfg->width>>1,cfg->height>>1);
temp_PSNR[2] = imagePSNR(encoder->in.cur_pic.vData,encoder->in.cur_pic.vRecData,cfg->width>>1,cfg->height>>1);
printf("[%d] %c-frame PSNR: %2.2f %2.2f %2.2f\n", encoder->frame, "IPB"[encoder->in.cur_pic.type%3],
printf("[%d] %c-frame PSNR: %2.4f %2.4f %2.4f\n", encoder->frame, "IPB"[encoder->in.cur_pic.type%3],
temp_PSNR[0],temp_PSNR[1],temp_PSNR[2]);
PSNR[0]+=temp_PSNR[0];
PSNR[1]+=temp_PSNR[1];
@ -174,7 +175,7 @@
}
/* Coding finished */
printf(" Processed %d frames, AVG PSNR: %2.2f %2.2f %2.2f\n", encoder->frame,PSNR[0]/encoder->frame,PSNR[1]/encoder->frame,PSNR[2]/encoder->frame);
printf(" Processed %d frames, AVG PSNR: %2.4f %2.4f %2.4f\n", encoder->frame,PSNR[0]/encoder->frame,PSNR[1]/encoder->frame,PSNR[2]/encoder->frame);
fclose(input);
fclose(output);

View file

@ -192,7 +192,7 @@ void init_encoder_control(encoder_control* control,bitstream* output)
control->stream = output;
}
void init_encoder_input(encoder_input* input,FILE* inputfile, uint32_t width, uint32_t height)
void init_encoder_input(encoder_input* input,FILE* inputfile, int32_t width, int32_t height)
{
int i;
input->file = inputfile;

View file

@ -33,10 +33,10 @@ enum { FORMAT_400 = 0, FORMAT_420, FORMAT_422, FORMAT_444 };
typedef struct
{
FILE* file;
uint32_t width;
uint32_t height;
uint32_t height_in_LCU;
uint32_t width_in_LCU;
int32_t width;
int32_t height;
int32_t height_in_LCU;
int32_t width_in_LCU;
picture cur_pic;
uint8_t video_format;
} encoder_input;
@ -88,7 +88,7 @@ typedef struct
} transform_info;
void init_encoder_control(encoder_control* control,bitstream* output);
void init_encoder_input(encoder_input* input,FILE* inputfile, uint32_t width, uint32_t height);
void init_encoder_input(encoder_input* input,FILE* inputfile, int32_t width, int32_t height);
void encode_one_frame(encoder_control* encoder);

View file

@ -129,26 +129,26 @@
#define PSNRMAX (255.0*255.0)
//Calculates image PSNR value
double imagePSNR(uint8_t *frame1, uint8_t *frame2, uint32_t x, uint32_t y)
double imagePSNR(uint8_t *frame1, uint8_t *frame2, int32_t x, int32_t y)
{
uint64_t MSE=0;
uint64_t MSEtemp=0;
int64_t MSE=0;
int64_t MSEtemp=0;
double psnr=0.0;
double pixels = x*y;
int32_t index;
//Calculate MSE
for(index=x*y-1;index>=0;index--)
for(index = 0; index < x*y; index++)
{
MSEtemp=frame1[index]-frame2[index];
MSE+=MSEtemp*MSEtemp;
}
MSE/=x*y;
//Avoid division by zero
if(MSE==0) return 99.0;
//The PSNR
psnr=10*log10(PSNRMAX/MSE);
psnr=10*log10(PSNRMAX/((double)MSE/pixels));
//Thats it.
return psnr;
@ -346,6 +346,7 @@ uint32_t SAD16x16(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stri
block += iOffsetOrg;
block2 += iOffsetCur;
}
*/
uint32_t sum=0;
for(y=0;y<16;y++)
@ -369,6 +370,7 @@ uint32_t SAD16x16(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stri
sum+=abs((int32_t)block[i+14]-(int32_t)block2[ii+14]);
sum+=abs((int32_t)block[i+15]-(int32_t)block2[ii+15]);
}
return sum;
}

View file

@ -21,7 +21,7 @@ uint32_t SAD32x32(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stri
uint32_t SAD16x16(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stride2);
uint32_t SAD8x8(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stride2);
uint32_t SAD4x4(int16_t *block,uint32_t stride1,int16_t* block2, uint32_t stride2);
double imagePSNR(uint8_t *frame1, uint8_t *frame2, uint32_t x, uint32_t y);
double imagePSNR(uint8_t *frame1, uint8_t *frame2, int32_t x, int32_t y);
/** \defgroup picture_group Picture handler group
* This group contains all picture related stuff