0

我写了这段代码:

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

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

[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
4

1 回答 1

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

确保InputImage和的大小ReconstructedImage相同。

于 2017-05-16T19:10:57.763 回答