Unable to read image.JPG file

22 次查看(过去 30 天)
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 个评论
Nataliya
Nataliya 2016-12-16
Its returning 0 (zero)
José-Luis
José-Luis 2016-12-16
编辑:José-Luis 2016-12-16
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?

请先登录,再进行评论。

采纳的回答

Jan
Jan 2016-12-16
编辑:Jan 2016-12-17
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 个评论
Walter Roberson
Walter Roberson 2016-12-17
"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 2016-12-17
编辑:Jan 2016-12-17
@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.

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2016-12-17
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 个评论
Image Analyst
Image Analyst 2016-12-17
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));

请先登录,再进行评论。


Holly Pothier
Holly Pothier 2018-4-16

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 个评论
Guillaume
Guillaume 2018-4-16
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by