function [ Rate, SNR ] = mComputeDCT8x8RateAndSNR( image, weight_scale ) image_size = prod( size( image ) ); image_mean = round( mean(mean(image)) ); M = 8; [ reconstructed_image, quantized_coefficients ] = mOptimalDCT8x8ImageAndCoeffs( image, weight_scale ); signal = mean( mean( image.^2 ) ); noise = mean( mean( (image-reconstructed_image).^2 ) ); SNR = 10*log10( signal/noise ); [ PDF_update range_update RLE_count RLE_update ] = mComputeRLEPDF( quantized_coefficients, 1, M ); % x*log(x) = log(x^x) PlogP = log( PDF_update.^PDF_update)./log(2); Rate = -sum(sum( PlogP' ))*RLE_count/image_size;