PSNR&&SSIM(MATLAB)

这篇博客主要介绍了如何在MATLAB中计算图像的峰值信噪比(PSNR)和结构相似度指数(SSIM)。在'PSNR.m'文件中,详细说明了如何读取并计算result目录下图片的PSNR。而在'SSIM.m'部分,讲解了通过命令行输入图像文件,对比两张图片的SSIM值的过程。
摘要由CSDN通过智能技术生成

一、PSNR.m

clear;
name = 'balloons336';
file_path = ['result\',name,'\'];%图像文件夹路径
gndname = 'balloons6_1.bmp';
gnd = imread(strcat(file_path,gndname));%读ground-truth图像
img_path_list = dir(strcat(file_path,'*.bmp'));%获取该文件夹中所有bmp格式的图像
img_num = length(img_path_list);%获取图像总数量
fid = fopen(strcat(file_path,'psnr.txt'),'w');
for i = 1:img_num %逐一读取图像
   image_name = img_path_list(i).name;%图像名
   if ~strcmp(image_name,gndname) %字符串比较,如果不相等...
       image = imread(strcat(file_path,image_name));
       [PSNR,MSE]=GetPSNR(image,gnd);
       fprintf(fid,' %f \t\t %f \t\t  %s \r\n',PSNR,MSE,image_name);
   end
end
fclose(fid);

注释:第二行name= ,为 result\ 的文件名

           第三行file_path= ,这里result为PSNR.m同一目录下的文件,可根据实际情况更改。

           第四行gndname= ,这里为ground-truth,存放路径为 result\balloons336\ 。

二、SSIM.m

function [mssim, ssim_map] = ssim(img1, img2, K, window, L)
 
%========================================================================
%SSIM Index, Version 1.0
%Copyright(c) 2003 Zhou Wang
%All Rights Reserved.
%
%The author is with Howard Hughes Medical Institute, and Laboratory
%for Computational Vision at Center for Neural Science and Courant
%Institute of Mathematical Sciences, New York University.
%
%----------------------------------------------------------------------
%Permission to use, copy, or modify this software and its documentation
%for educational and researc
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值