Unable to read image.JPG file

31 visualizzazioni (ultimi 30 giorni)
Nataliya
Nataliya il 16 Dic 2016
Commentato: Guillaume il 16 Apr 2018
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 Commenti
Nataliya
Nataliya il 16 Dic 2016
Its returning 0 (zero)
José-Luis
José-Luis il 16 Dic 2016
Modificato: José-Luis il 16 Dic 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?

Accedi per commentare.

Risposta accettata

Jan
Jan il 16 Dic 2016
Modificato: Jan il 17 Dic 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 Commenti
Walter Roberson
Walter Roberson il 17 Dic 2016
"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 il 17 Dic 2016
Modificato: Jan il 17 Dic 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.

Accedi per commentare.

Più risposte (2)

Walter Roberson
Walter Roberson il 17 Dic 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 Commento
Image Analyst
Image Analyst il 17 Dic 2016
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));

Accedi per commentare.


Holly Pothier
Holly Pothier il 16 Apr 2018

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 Commento
Guillaume
Guillaume il 16 Apr 2018
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.

Accedi per commentare.

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by