how can i solve the error of reading permission during loading of number of images from a folder

d=dir('d:\train2');
for i=1:4
fname=d(i).name;
z=imread(fname,'bmp');
end
this code is giving error
??? Error using ==> imread at 358 Can't open file "." for reading; you may not have read permission.
help me out to solve this error please

 Accepted Answer

Looks to me as if you're trying to open the directory itself ('./') as if it was an image. The return from dir called on a directory will contain both the directory ('.') and its parent directory ('..'). Either you have to check that what you're trying to open is an image, or list only the images.
HTH

3 Comments

thank u..i extracted only the images.. my code is working now
Hi. I have the same problem but I didn't understand your solution. I am new to matlab.So can you please explain in a little bit more details?
projectdir = 'd:\train2';
d = dir(projectdir);
d([d.isdir]) = []; %remove all folders including . and ..
num_files = numel(d);
all_images = cell(num_files,1);
file_okay = false(num_files,1);
for K = 1 : num_files
fname = fullfile(projectdir, d(K).name);
try
all_images{K} = fread(fname);
file_okay(K) = true;
catch ME
warning('file "%s" is not a readable image', fname);
end
end
all_images = all_images(file_okay);

Sign in to comment.

More Answers (2)

Try
d=dir('d:\train2\*.bmp');

3 Comments

Hello I have the same issue can you share with me how you solved it ?
tu1=imread('C:\Users\Mostwanted\Desktop\Upgrade 03062016\Upgrade 03062016\Adaptive Exposure\AEx2\','*.jpg');
projectdir = 'C:\Users\Mostwanted\Desktop\Upgrade 03062016\Upgrade 03062016\Adaptive Exposure\AEx2';
d = dir(fullfile(projectdir, '*.jpg'));
num_files = numel(d);
all_images = cell(num_files,1);
file_okay = false(num_files,1);
for K = 1 : num_files
fname = fullfile(projectdir, d(K).name);
try
all_images{K} = fread(fname);
file_okay(K) = true;
catch ME
warning('file "%s" is not a readable image', fname);
end
end
all_images = all_images(file_okay);

Sign in to comment.

I have the same issue, and finally I find out my problem: I opened too much files without closing them. https://www.mathworks.com/matlabcentral/answers/124335-caught-std-exception-exception-message-is-message-catalog-matlab-builtins-was-not-loaded-from-th

1 Comment

Running out of file slots should never result in the error message reported here. The problem here is that the user assumed that the first two names returned were . and .. but Windows with NTFS does not make any promises about the order of files, and in practice there are several valid filename characters that can sort before .

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!