Can any one help me to fix error with imread()?

2 views (last 30 days)
The code is...
imgListFile = fopen('image_class.txt', 'r');
F = zeros(6, 24); L = cell(6, 1);
tline = fgetl(imgListFile); currentLine = 1;
while ischar(tline)
disp(tline)
splittedLine = regexp(tline, ',[ ]*', 'split');
imagePath = fullfile('imgs', splittedLine{1});
I = imread(imagePath);
f = sfta(I, 4);
F(currentLine, :) = f;
% Store the image label.
L{currentLine} = splittedLine{2};
tline = fgetl(imgListFile);
currentLine = currentLine + 1;
end;
fclose(imgListFile);
I am getting following error...
Error using imread (line 347)
Can't open file "imgs" for reading;
you may not have read permission.
Error in classifymy (line 12)
I = imread(imagePath);
I have checked read permission, but it is there? Not able to trace where is problem? Thanks in advance

Answers (2)

Geoff Hayes
Geoff Hayes on 18 Oct 2015
Nilima - it sounds like you don't have read permissions for this file (though is imgs the correct name for it?). To find out, look at the permissions for this file. If using a Linux or Unix OS, open a terminal window and go to the directory where this file is located. Type
ls -ag
to list all of the files in this directory along with their permissions. In order for you to have read permissions to this file you will need to see something like
-r--r--r--@ 1 staff 43279 15 Mar 2015 myImage.gif
The r is for read. If you don't see it for the appropriate group that you are in, then you will have to add it using chmod to change the file's permissions.
If using a Windows operating system, then you can use Explorer to open the properties of the file which you can then add the read permission to.
  1 Comment
Nilima
Nilima on 19 Oct 2015
Dear, Geoff Sir, Thanks for reply. I have read and write permission for this folder. Still I don't know why this error coming?

Sign in to comment.


Walter Roberson
Walter Roberson on 18 Oct 2015
At some point in the file you are encountering a line which is empty before its first comma. That is leaving you with an empty splittedLine{1} and the fullfile() is then leaving "imgs" as the directory name rather than converting it to "imgs\" or "imgs/" with no following file name.
  5 Comments
Nilima
Nilima on 19 Oct 2015
Edited: Nilima on 19 Oct 2015
Sorry..File is attached now...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!