Unable to read image.JPG file

I am getting the error
Error using imread (line 349)
File "E:\GT\out_of_focus0016.JPG" does not exist.
How can i resolve this error. i have the image in the folder by this name. Actually the problem is, its reading the images having .jpg extension but giving error for images having .JPG (capital) extension. How can I resolve this. Please help.

4 Comments

This is the complete code:
smapName = files(k).name;
smapImg = imread(fullfile(SMAP, smapName));
gtName = strrep(smapName, smapSuffix, gtSuffix);
gtImg = imread(fullfile(GT, gtName));
I am gettng the error at the last line.
If you get a file does not exist error then you must have put the filename together incorrectly in the string.
What does
exist( fullfile(GT, gtName), 'file' )
return?
Its returning 0 (zero)
José-Luis
José-Luis on 16 Dec 2016
Edited: José-Luis on 16 Dec 2016
From the documentation:
" exist name returns the type of name as a number. This list describes the type associated with each value:
0 — name does not exist."
Could you copy the file in your current folder and try again?

Sign in to comment.

 Accepted Answer

Jan
Jan on 16 Dec 2016
Edited: Jan on 17 Dec 2016
Windows is not case-sensitive for file names. Matlab states clearly, that the file "E:\GT\image0016.JPG" does not exist. Therefore your opinion that this file is existing must be wrong. Therefore this error can be solved only by providing the correct file name.
[EDITED] Please post the output of:
FileList = dir('Proposed\*.jpg');
for k = 1:numel(FileList)
NameC = FileList(k).name;
NameD = uint16(NameC);
fprintf('\n%s:\n', NameC);
fprintf('%d ', NameD);
end

7 Comments

Please see the images in the folder. The loop is working perfectly for first 15 images but gives error at 16th image having .JPG extension.
Your error is pointing to
E:\GT\image0016.JPG
not existing. The files you highlight are nothing like that name.
Edited the error.. actually i wrote it generically
Well if you've edited it correctly it still doesn't point to the file shown, which is in a folder called 'Proposed'. JPG or jpg makes no difference.
What does
fid = fopen( ... )
return when you put the filename in there exactly as it is in your code?
When testing I managed to create a situation in which I pasted a filename from its properties dialog in Windows Explorer into Matlab and it looks exactly as it should, but Matlab claims the file doesn't exist. Then I typed the filename in and found that there is a hidden character at the front of the one I copied. If you are getting a file listing programmatically though this type of thing should not happen as far as I am aware.
I agree with Adam and was going to suggest it -- a hidden character. So how did you get files in this:
smapName = files(k).name;
Did you use dir(), like recommended in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F or did you somehow create that structure array on your own?
"Windows is not case-sensitive for teh file names"
That is not entirely correct. In MS Windows, whether a file name component is case-sensitive or not depends on both the API used to access it and on the file system it is on. See http://superuser.com/questions/266110/how-do-you-make-windows-7-fully-case-sensitive-with-respect-to-the-filesystem
Jan
Jan on 17 Dec 2016
Edited: Jan on 17 Dec 2016
@Walter: You are right: After setting a registry flag you can consider the case on NFS network drives or with CgyWin commands, when the drive is mounted with the POSIX flag, as far as I understand the discussion. I hope the OP does tell us, if something like this happens. :-)
@Nataliya: See [EDITED] to detect hidden characters in the file names.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 17 Dec 2016
The .name you get back from dir() does not include the directory. You need to fullfile() the directory information into place before you can open the file.

1 Comment

She was. She said:
"This is the complete code:
smapName = files(k).name;
smapImg = imread(fullfile(SMAP, smapName));
gtName = strrep(smapName, smapSuffix, gtSuffix);
gtImg = imread(fullfile(GT, gtName));

Sign in to comment.

Hello, I am getting the same error. However, when I check with the recommended 'exist', the output is 2. Which, according to the documentation, means: "2 — name is a file with extension .m, .mlx, or .mlapp, or name is the name of a file with a non-registered file extension (.mat, .fig, .txt)." How can I move forward?

I am confused imread is in a loop, and all the files are .jpg files. However, when I loop, some of the images result in the error. Here is the relevant portion of my code. Thank you.

display ('top'); %Get list of all files in the folder with the desired file name pattern filePattern = fullfile(myFolder, '*.jpg'); %find files that are .jpg jpegFiles = dir(filePattern); %dir = list all files that match .jpg (from filePattern)

if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; end

display ('before loop'); for k = 1:length(jpegFiles) %loop through all .jpg files display ('inside loop'); baseFileName = jpegFiles(k).name; %name of .jpgs (indexed individually (k)); Ex: SDC10705_RS.jpg fullFileName = fullfile(myFolder, baseFileName); %fullfile builds filename from parts = myfolder\baseFileName (full path of ^) fprintf(1, 'Now reading %s\n', fullFileName); imageArray = imread(fullFileName); %read specific FULLfilename from store of .jpg files %this should be the full

    %Rotate                                   
    display ('rotation');
    %raw= jpegFiles(k).name;
    I = imread(jpegFiles(k).name); %must have imread for next step to work (rotation of I)
    R = imrotate(I, 355, 'bicubic'); %put angle and type of rotation here. 'bicubic' works best/ least distortion                           
    imshow(R); %display image
    %drawnow; %force display to update immediately
    %Break up fileparts to allow saving with '_rotate' extension when looping through files
    [tmp_path, tmp_name, tmp_ext] = fileparts(fullFileName); %separating fullFileName, into path, name, and ext (.jpg) (pretty much opposite of fullfile)
                                                             %need to do this so .jpg is at the end
    fullFileName_rotate = [tmp_path, filesep, tmp_name, '_rotate',tmp_ext];
    imwrite(R, fullFileName_rotate); %new rotated image
                                     %saved as filename_rotate

1 Comment

Please start your own question rather than highjacking somebody's else. You can link to this question in your own question if you feel they are related.

Sign in to comment.

Categories

Tags

No tags entered yet.

Asked:

on 16 Dec 2016

Commented:

on 16 Apr 2018

Community Treasure Hunt

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

Start Hunting!