0% found this document useful (0 votes)
39 views1 page

Function PSNR

The document defines two functions: 1) psnr calculates the peak signal-to-noise ratio between two images by taking the square root of the mean squared error and converting to decibels. 2) MSE calculates the mean squared error between two images by summing the squared differences between corresponding pixel color values (red, green, blue) and dividing by the number of pixels. It returns an RGB record with the MSE values or indicates an error if the number of pixels is 0.

Uploaded by

santri87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Function PSNR

The document defines two functions: 1) psnr calculates the peak signal-to-noise ratio between two images by taking the square root of the mean squared error and converting to decibels. 2) MSE calculates the mean squared error between two images by summing the squared differences between corresponding pixel color values (red, green, blue) and dividing by the number of pixels. It returns an RGB record with the MSE values or indicates an error if the number of pixels is 0.

Uploaded by

santri87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

function psnr (a, b: pbyte; length: longword): real;

var
mse, k: real;
c: longword;
begin
mse := 0;
k := 1 / length;
for c := 0 to (length - 1) do
mse := mse + Sqr(a[c] - b[c]);
mse := mse * k;
if mse > 0 then
Result := 10 * log10(sqr(255) / mse)
else
Result := 100;
end;

function MSE(I, I1 : TCanvas; W, H, L : Integer) : TRGBRecord;


var M : Integer;
x, y : Integer;
begin
Result.R := 0;
Result.G := 0;
Result.B := 0;

M := (W-2*L)*(H-2*L);

for x := L to W-1-L do
for y := L to H-1-L do
begin
Result.R := Result.R + sqr(Red(I.Pixels[x, y]) - Red(I1.Pixels[x,
y]));
Result.G := Result.G + sqr(Green(I.Pixels[x, y]) - Green(I1.Pixels[x,
y]));
Result.B := Result.B + sqr(Blue(I.Pixels[x, y]) - Blue(I1.Pixels[x,
y]));
end;

if M <> 0 then
begin
Result.R := Result.R / M;
Result.G := Result.G / M;
Result.B := Result.B / M;
end
else
begin // indicates an arror. M = 0
Result.R := -1;
Result.G := -1;
Result.B := -1;
end;
end;

You might also like