I Get error in imread

9 Ansichten (letzte 30 Tage)
Abhijith Nuchin
Abhijith Nuchin am 22 Okt. 2014
Beantwortet: Image Analyst am 22 Okt. 2014
code:
image=uigetfile('*.bmp','Select the image');
B= imread(image, 'bmp'); figure(1),imshow(B);
Output
??? Error using ==> imread at 401 File "boat.bmp" does not exist.
Error in ==> Untitled3 at 3 B= imread(image, 'bmp');
The file exists..it takes input if i manually give filename, like this
A='C:\Users\Omkar\Desktop\boat.bmp'; B= imread(A, 'bmp'); figure(1),imshow(B);

Akzeptierte Antwort

Orion
Orion am 22 Okt. 2014
Bearbeitet: Orion am 22 Okt. 2014
you just need to give the full path of your file
[filename,pathname]=uigetfile('*.bmp','Select the image');
B= imread(fullfile(pathname,filename), 'bmp');
figure(1);
imshow(B);
  1 Kommentar
Abhijith Nuchin
Abhijith Nuchin am 22 Okt. 2014
Thank u very much...i am a newbie

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 22 Okt. 2014
Do not use image as the name of a variable - or else you will destroy a built-in function also called image. Also try not to turn your code into an alphabet soup of variables - use descriptive variable names, not just single letters or cryptic shorthand for everything. It will make your code more maintainable and understandable. See the much more robust code below:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
rgbImage = imread(fullFileName);
imshow(rgbImage);

Kategorien

Mehr zu MATLAB Support Package for USB Webcams finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by