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

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.

댓글을 달려면 로그인하십시오.

답변 (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

[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

댓글을 달려면 로그인하십시오.

질문:

2017년 5월 9일

편집:

2017년 5월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by