I Get error in imread

8 ビュー (過去 30 日間)
Abhijith Nuchin
Abhijith Nuchin 2014 年 10 月 22 日
回答済み: Image Analyst 2014 年 10 月 22 日
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);

採用された回答

Orion
Orion 2014 年 10 月 22 日
編集済み: Orion 2014 年 10 月 22 日
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 件のコメント
Abhijith Nuchin
Abhijith Nuchin 2014 年 10 月 22 日
Thank u very much...i am a newbie

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 10 月 22 日
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);

カテゴリ

Help Center および File ExchangeMATLAB Support Package for USB Webcams についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by