2017-05-16 63 views
0

我写了这个代码:提示用户在MATLAB GUI选择文件夹图像计算PSNR和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); 

如何修改编码提示用户选择图像的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 

回答

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

+0

为了您的信息,这两个文件都在该文件夹中可用。当我运行编码时不提示用户输入,它工作正常。但是,在我修改编码以提示用户输入之后,它会给出矩阵尺寸不一致的错误。任何解决方案? – jolene

+0

这个错误是显示上面发布代码的哪一行? –

+0

如果在MSE = sum(sum((InputImage-ReconstructedImage)。^ 2))/(M * N)中显示错误,那么这是因为InputImage和ReconstructedImage的矩阵尺寸不同。查看matlab工作区来确认。 –