【问题标题】:Prompt user to select image from folder in MATLAB GUI to calculate PSNR and MSE提示用户从 MATLAB GUI 中的文件夹中选择图像以计算 PSNR 和 MSE
【发布时间】:2017-05-16 18:26:30
【问题描述】:

我已经写了这段代码:

InputImage=imread('ground truth 1.jpg');
ReconstructedImage=imread('final1.jpg');
n=size(InputImage);
 M=n(1);
 N=n(2);
 MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
 fprintf('\nMSE: %7.2f ', MSE);
 fprintf('\nPSNR: %9.7f dB', PSNR);

如何修改编码以提示用户从文件夹中为InputImageOutputImage 选择图像?我以前尝试过这样的事情

[InFile, InPath] = uigetfile('*.jpg', 'Import image file:');
if ~ischar(InFile)
  disp('User aborted file import');
  return;
end
[OutFile, OutPath] = uigetfile('*.jpg', 'Export image file:', InPath);
if ~ischar(OutFile)
  disp('User aborted file export');
  return;
end
InFile  = fullfile(InPath, InFile);
OutFile = fullfile(OutPath, OutFile);

但我得到了一个错误:

Matirx dimension not agree error

【问题讨论】:

    标签: matlab user-input matlab-guide mse


    【解决方案1】:

    这段代码可以正常工作。

    [InFile, InPath] = uigetfile('*.jpg', 'Import image file:');
    if ~ischar(InFile)
      disp('User aborted file import');
      return;
    end
    
    [OutFile, OutPath] = uigetfile('*.jpg', 'Export image file:', InPath);
    if ~ischar(OutFile)
      disp('User aborted file export');
      return;
    end
    InFile  = fullfile(InPath, InFile);
    OutFile = fullfile(OutPath, OutFile);
    
    InputImage=imread(InFile);
    ReconstructedImage=imread(OutFile);
    n=size(InputImage);
     M=n(1);
     N=n(2);
     MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
    PSNR = 10*log10(256*256/MSE);
     fprintf('\nMSE: %7.2f ', MSE);
     fprintf('\nPSNR: %9.7f dB', PSNR);
    

    确保InputImageReconstructedImage 的大小相同。

    【讨论】:

    • 供您参考,这两个文件都在文件夹中可用。当我在不提示用户输入的情况下运行编码时,它工作正常。但是在我修改编码以提示用户输入后,它给出了矩阵维度不同意错误。有什么解决办法吗?
    • 该错误显示在上面发布的代码的哪一行?
    • 如果MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);中显示错误,那是因为InputImageReconstructedImage的矩阵维度不同。查看 matlab 工作区以确认。
    • 代码现在可以正常工作了。还有一件事,如何在 MATLAB GUI 中的“编辑文本”上显示这些 PSNR 和 MSE 值?
    • set(handles.edit1, 'string', MSE); 其中edit1 是编辑文本的标签名称
    猜你喜欢
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2011-04-08
    • 2023-03-17
    • 2015-08-11
    相关资源
    最近更新 更多