MSE and PSNR

Feb 13, 2013 at 12:19 PM
I have two dds files (one is the original (BC1) and the other one is the modified version (also BC1) of the original) and I want to calculate the PSNR for them. I know that first I need to calculate MSE and I assume that I need to use ComputeMSE function to do that, but I don't know how to use it in my code. Could you provide me with an example to calculate PSNR of two dds files which are BC1 compressed? and how can I see the Texconv command-line for the examples.
Coordinator
Feb 13, 2013 at 9:08 PM
Based on reading this formula on Wikipedia:

Remember that PSNR is based on MSE and MSE is based on a comparison of something to something else. It's a relative statistic.

I don't have MSE being used by texconv as historically that's not been a usage scenario for it, but you could easily write a little command-line to do it.

Something basically like:
// Load the BC1 images
TexMetadata metadata;
ScratchImage bcImage1;
hr = LoadFromDDSFile( "mybc1A.dds", DDS_FLAGS_NONE, &metadata, bcImage1 );

ScratchImage bcImage2;
hr = LoadFromDDSFile( "mybc1B.dds", DDS_FLAGS_NONE, nullptr, bcImage2 );

// Compute MSE between the two images (image is converted to DXGI_FORMAT_R32G32B32A32_FLOAT to compute MSE)
float mse, mseV[4];
hr = ComputeMSE( *bcImage1.GetImage(0,0,0), *bcImage2.GetImage(0,0,0), mse, mseV );

float npixels = float(metadata.width) * float(metadata.height);

// Sum PSNR
float psnr;
if ( mse != 0 )
{
    mse /= npixels;
    psnr=10*log10(1.f / mse)
}
else
{
    psrn =99.f;
}