Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!n33g2000pri.googlegroups.com!not-for-mail
From: malin198409@gmail.com
Newsgroups: comp.soft-sys.matlab
Subject: Re: PSNR ?
Date: Tue, 25 Nov 2008 22:45:29 -0800 (PST)
Organization: http://groups.google.com
Lines: 27
Message-ID: <f8cd26a8-8cab-4f48-af85-509e3e6bee26@n33g2000pri.googlegroups.com>
References: <gef3t8$r8q$1@fred.mathworks.com>
NNTP-Posting-Host: 137.189.34.96
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1227681929 25296 127.0.0.1 (26 Nov 2008 06:45:29 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 26 Nov 2008 06:45:29 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: n33g2000pri.googlegroups.com; posting-host=137.189.34.96; 
	posting-account=8sSB7AkAAADOgUV6KloJvmWm9E3yPvq_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 
	1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 
	3.0.04506.648),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:503240


On Oct 31, 10:15=A0pm, "ABUTALA" <love.scre...@gmail.com> wrote:
> Can anyone reply with the sample code to calculate PSNR of two
> images in MATLAB?
>
> thanks

Matlab Sorce code is listed in the following. and the range of the
value of the two image A and B is 0~255:

function PSNR(A,B)

if A =3D=3D B
   error('Images are identical: PSNR has infinite value')
end

max2_A =3D max(max(A));
max2_B =3D max(max(B));
min2_A =3D min(min(A));
min2_B =3D min(min(B));

if max2_A > 255 || max2_B > 255 || min2_A < 0 || min2_B < 0
  error('input matrices must have values in the interval [0,255]')
end

error_diff =3D A - B;
decibels =3D 20*log10(255/(sqrt(mean(mean(error_diff.^2)))));
disp(sprintf('PSNR =3D +%5.2f dB',decibels))