MATLAB Answers

How to read multiple images from a folder where images have names like "3_nouvel-​obs_hbhnr3​00_constru​ctedPdf_No​uvelobs240​2PDF.clean​.png" , "7_nouvel-​obs_hbhnr3​00_constru​ctedPdf_No​uvelobs240​2PDF.clean​.png" and so on.

2 views (last 30 days)
Kavita on 12 Jul 2019
Answered: Srivardhan Gadila on 17 Jul 2019
myfolder='G:\Matlab Code-IIITA\DATASETS\nouvel_obs_2402_clean-1.0\input';
%% Also tried this : pngfiles=dir(fullfile(myfolder,'\*png'));
for i = 1:5
img{i} = imread(pngfiles(i).name);
Above code is giving error : Tried it on MATLAN R2018a:
I want to read the .png files present in a folder:
Error is
Error using imread>get_full_filename (line 516)
File "100_nouvel-obs_hbhnr300_constructedPdf_Nouvelobs2402PDF.clean.png" does not exist.
Error in imread (line 340)
fullname = get_full_filename(filename);
Error in trial (line 5)
img{i} = imread(pngfiles(i).name);
But when i check for pngfiles(1).name i get the following output.
>> pngfiles(1).name
ans =
Why i am not able to read/ perform imshow to display images

  1 Comment

dpb on 12 Jul 2019
I'm suspicious of the second dot in the filename--try renaming the file to something w/o that and see if it won't then work successfully.

Sign in to comment.

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 17 Jul 2019
The error is due to the input argument provided to the “imread” function. The input pngfiles(i).name” which is equal to
100_nouvel-obs_hbhnr300_constructedPdf_Nouvelobs2402PDF.clean.png'’ (for i=1 in your case) is not the complete path of the PNG image file you are trying to load.
It can work only in the following scenarios :
  • The files are in the MATLAB’s path
  • Or the current working directory contains the files which you are loading.
In all other cases provide the complete path of the image file to the “imread” function’s argument. ('G:\Matlab Code-IIITA\DATASETS\nouvel_obs_2402_clean-1.0\input\100_nouvel-obs_hbhnr300_constructedPdf_Nouvelobs2402PDF.clean.png')


Sign in to comment.

Sign in to answer this question.

Translated by