提示用户从 MATLAB GUI 中的文件夹获取 select 图像以计算 PSNR 和 MSE

Prompt user to select image from folder in MATLAB GUI to calculate PSNR and MSE

我写过这段代码:

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);

如何修改编码以提示用户从文件夹中 select 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

此代码可以正常工作。

[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 的大小相同。