Q: Prompt user to select image from folder in MATLAB GUI to calculate PSNR and MSE I have written this code:
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);

How do I modify the coding to prompt the user to select an image for InputImage and OutputImage from a folder? I have tried something like this before
[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);

but I got an error:
Matirx dimension not agree error


A: This code will work just fine.
[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);

Make sure the size of InputImage and ReconstructedImage are same.
