我写了这段代码:
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
答案 0 :(得分: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
的大小相同。