I Get error in imread

1 view (last 30 days)
Abhijith Nuchin
Abhijith Nuchin on 22 Oct 2014
Answered: Image Analyst on 22 Oct 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);

Accepted Answer

Orion
Orion on 22 Oct 2014
Edited: Orion on 22 Oct 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);

More Answers (1)

Image Analyst
Image Analyst on 22 Oct 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);

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!