PSNR&&SSIM(MATLAB)

一、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
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
MATLAB提供了计算图像质量评价指标PSNRSSIM的函数,可以通过以下步骤使用MATLAB GUI来计算: 1. 在MATLAB创建一个GUI界面,在界面上创建两个按钮,一个用于选择参考图像,另一个用于选择待评价的图像。 2. 为每个按钮添加回调函数,使其分别调用MATLAB的`uigetfile`函数用于选择参考图像和待评价图像。 3. 在GUI界面上添加一个用于显示结果的文本框。 4. 编写一个计算PSNRSSIM的函数,该函数的输入为参考图像和待评价图像的路径,输出为PSNRSSIM的值。 5. 在每个按钮的回调函数,调用计算函数并将结果显示在文本框。 下面是一个简单的示例代码来实现上述步骤: ```matlab function psnr_ssim_gui % 创建GUI界面 fig = uifigure('Name', 'PSNR and SSIM Calculation'); % 创建显示结果的文本框 resultTextBox = uitextarea(fig, 'Position', [50, 100, 200, 100]); % 创建选择参考图像的按钮 refButton = uibutton(fig, 'Position', [50, 250, 200, 30], 'Text', 'Select Reference Image', 'ButtonPushedFcn', @(src, event) selectImage(src, event, 'reference')); % 创建选择待评价图像的按钮 evalButton = uibutton(fig, 'Position', [50, 300, 200, 30], 'Text', 'Select Evaluation Image', 'ButtonPushedFcn', @(src, event) selectImage(src, event, 'evaluation')); function selectImage(src, event, imageType) % 弹出文件选择对话框 [filename, pathname] = uigetfile({'*.jpg;*.png', 'Image Files (*.jpg, *.png)'}, 'Select an image'); if ~isequal(filename, 0) % 获取图像的完整路径 imagepath = fullfile(pathname, filename); % 根据图像类型,更新参考图像或待评价图像的路径 if isequal(imageType, 'reference') refImagePath = imagepath; else evalImagePath = imagepath; end end end function calculatePSNR_SSIM % 计算PSNRSSIM [psnrValue, ssimValue] = calculate(refImagePath, evalImagePath); % 将结果显示在文本框 resultText = sprintf('PSNR: %.2f\nSSIM: %.2f', psnrValue, ssimValue); resultTextBox.Value = resultText; end function [psnrValue, ssimValue] = calculate(refImagePath, evalImagePath) % 读取图像 refImage = imread(refImagePath); evalImage = imread(evalImagePath); % 在此编写计算PSNRSSIM的代码 % 这里只是举例计算了图像的差异,你需要根据实际需要进行计算 diff = abs(evalImage - refImage); mse = mean(diff(:).^2); maxval = 255; psnrValue = 10 * log10(maxval^2 / mse); % 这里的ssimValue也只是个示例,你需要根据实际需要进行计算 ssimValue = ssim(evalImage, refImage); end end ``` 以上代码创建了一个简单的GUI界面,包括选择参考图像和待评价图像的按钮,并显示计算结果的文本框。当用户点击按钮时,会调用相应的回调函数来选择图像,并调用计算函数来计算PSNRSSIM的值,最后将结果显示在文本框。请注意,这只是一个示例代码,你需要根据实际需要进行适当的修改和完善。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值