How to request for user input for the following code? How do I modify the matlab code below to prompt user to choose images from folder for InputImage and OutputImage?

InputImage=imread('a.jpg');
OutputImage=imread('b.jpg'); whos
n=size(InputImage);
M=n(1);
N=n(2);
MSE = sum(sum((InputImage-OutputImage).^2))/(M*N);
PSNR = 10*log10(255*255/MSE);
fprintf('\nMSE: %7.2f ', MSE);
fprintf('\nPSNR: %9.7f dB', PSNR);

2 Comments

try this to allow user to select image from his device
[filename,path]=uigetfile('*.png','file selector');
Image=strcat(path,filename);
Img=imread(Image);
@Khaled Al-Faleh: Do not use the term "path" as a variable, because this is an important Matlab function. Such shadowing can cause very strange results during debugging. fullfile is smarter than strcat, because it considers the file separators.

Sign in to comment.

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

1 Comment

[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);
n=size(InFile);
M=n(1);
N=n(2);
MSE = sum(sum((InFile-OutFile).^2))/(M*N);
PSNR = 10*log10(255*255/MSE);
fprintf('\nMSE: %7.2f ', MSE);
fprintf('\nPSNR: %9.7f dB', PSNR);
@Jan Simon, could you please check my code? Cause I'm having matrix dimension not agree error

Sign in to comment.

Asked:

on 9 May 2017

Edited:

on 9 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!