MATLAB Answers

Kavita
0

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.

Asked by Kavita
on 12 Jul 2019
Latest activity Answered by Srivardhan Gadila on 17 Jul 2019
myfolder='G:\Matlab Code-IIITA\DATASETS\nouvel_obs_2402_clean-1.0\input';
pngfiles=dir(fullfile(myfolder,'\*_nouvel-obs_hbhnr300_constructedPdf_Nouvelobs2402PDF.clean.png'));
%% Also tried this : pngfiles=dir(fullfile(myfolder,'\*png'));
for i = 1:5
img{i} = imread(pngfiles(i).name);
end
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 =
'100_nouvel-obs_hbhnr300_constructedPdf_Nouvelobs2402PDF.clean.png'
Why i am not able to read/ perform imshow to display images

  1 Comment

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.

1 Answer

Answer by Srivardhan Gadila on 17 Jul 2019

Hi,
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')

  0 Comments

Sign in to comment.