i want to read an image from my windows with imread in matlab. my image name is "chest.jpg" but when i read I = imread('chest.jpg'); it shows errors :
File "chest.jpg" does not exist.
and
fullname = get_full_filename(filename);
how can I read my image from my folder?
If you image is in 'project_folder/another_folder/.../' you must use
imread('project_folder/another_folder/.../chest.jpg')
I suggest to use a relative path if the image is inside the script folder or in some internal folder. If it is in an independent path you can use an absolute path.
Related
How to get Matlab's path to matlab.settings?
On Unix/Mac this folder is usually ~/.matlab/R20xx/.
It's also where javaclasspath.txt is located.
I want to get it programmatically inside Matlab.
This is obtained in a system-independent way by using the prefdir command
disp(prefdir)
%// /Users/suever/.matlab/R2015b
I have the absolute path of an image myabspath
D:\myimages\venus\surface\im0012.jpg
I have tried
im=imread(myabspath);
but doesn't work because seems that imread accept only the name of a file in the current working directory.
I have also tried
f=load(myabspath);
But get an error "Argument must contain a string".
Seems a pretty basilar operation but unfortunately I haven't found the solution.
EDIT
Seems that the problem is caused by the fact myabspathis not a regular String but a cell, I have tried to use
myabspath=cellstr(myabspath)
but I continue to receive the error that tell me that myabspath is not a string, but if I call
display(myabspath)
I see the right path. Any solution?
If you have a cell that contains the String path, you don't need any conversion, is enough access the content of the cell using {index}.
Eg
if you have to get the first element use myabspath{1}
imread is able to read images from absolute paths
It seems strange.
Did you get a specific error message?
Does the image actually exists?
Did you, perhaps, write a "your own" imread function which overrides the "MatLab" one?
According to MatLab (R2012b) help, imread also accepts "full pathname"
imread Read image from graphics file.
A = imread(FILENAME,FMT) reads a grayscale or color image from the file
specified by the string FILENAME. If the file is not in the current
directory, or in a directory on the MATLAB path, specify the full
pathname.
I've replicated your folder structure, I did not add it to the MatLab path, nevertheless and I've been able to read an image with imread by specifying the full pathname.
This is the output I've got:
>> myabspath='D:\myimages\venus\surface\im0012.jpg'
myabspath =
D:\myimages\venus\surface\im0012.jpg
>> im=imread(myabspath);
>> whos
Name Size Bytes Class Attributes
im 421x500x3 631500 uint8
myabspath 1x36 72 char
I have a data folder in /home/me/project/data that contains image files. In project is my script. I wish to imread all the images in this file. When I do the following dirData = dir('.\data\*.jpg'); I get Error using imread (line 349). Is there a way to refer to this directory without having to specify the full path?
In my codes, there are some functions like imshow or fopen files that need addressing. When I use my program in MATLAB I use pwd like imshow([pwd '/image.jpg']) for addressing and the program run and work correctly, but when I compiled my program after installing it (redistribution) when I open shortcut in desktop, an error message appear with the title that my program can't find image.jpg . When I check the address of searching, it is like :
C:/User/Desktop/image.jpg
I read this page but I don't know how to use this addressing.
http://www.mathworks.com/matlabcentral/answers/59148-for-stand-alone-exe-how-do-i-include-a-folder-of-files-and-know-how-to-access-them
Beside It I don't know where I should add these files ( images and texts ) in MATLAB compiler options. In file required for your application to run or file installed with your application.
Thanks.
That is because your image is not located in your current path (i.e. the desktop in this case).
If you want to use images, you should include the image in deploytool's "shared Resources and helper files" and in your script/function reference the image as specified in the link, using:
if isdeployed
imagepath = [ctfroot filesep 'image.jpg'];
else
imagepath = [pwd filesep 'image.jpg'];
end
% Now use imagepath as if it was [pwd filesep 'image.jpg']
[A] = imread(imagepath);
Other option is including the file (image.jpg) in the same path as your final executable, since you are calling the image from pwd.
I start with Matlab and would like to know how could I access to a folder and get contents to access files and read them.
I have a variable in workspace tmpfolder that is equal to 'path to folder' but I don't find how could I make dir(tmpfolder) and get files, browse any file content to get a string value...
I would start with dir() and fopen().
More generally, try starting at the beginning: Working with Files and Folders.
If you have an image file in jpeg format in another folder named myimage and a text file called mytext, use:
prefix_image='myimage';
prefix_data='mytext';
fileformat='.jpg';
dataformat='.txt';
folder='C:\Users\khaled\Documents\MATLAB\';
image = imread(strcat(folder,prefix_image,fileformat));
data=textread(strcat(folder,prefix_data,fileformat),'%f');