error in reading frames

18 views (last 30 days)
Pat
Pat on 14 Mar 2012
i have 140 frames in E drive
path ='E:\surframes\';
files = dir(fullfile(path,'*.jpg'));
I = ((imread(fullfile(path,files(82:118).name))));
i want to read frames 82 to 118,but i get error as
Error using ==> imread at 372
File
"E:\surframes\23.jpg\24.jpg\25.jpg\26.jpg\27.jpg\28.jpg\29.jpg\3.jpg\30.jpg\31.jpg\32.jpg\33.jpg\34.jpg\35.jpg\36.jpg\37.jpg\38.jpg\39.jpg\4.jpg\40.jpg\41.jpg\42.jpg\43.jpg\44.jpg\45.jpg\46.jpg\47.jpg\48.jpg\49.jpg\5.jpg\50.jpg\51.jpg\52.jpg\53.jpg\54.jpg\55.jpg\56.jpg"
does not exist.
Error in ==> final at 26
I = ((imread(fullfile(path,files(82:118).name))));
my frames are ordered from 1 to 140
please help

Accepted Answer

Geoff
Geoff on 14 Mar 2012
You're constructing one filename out of lots of them. You're also assuming that the files are listed in order. You need to get the frame number from the file name.
Try this:
I = {};
for f = 1:length(files)
file = files(f).name;
frame = num2str( file(1:find(file,f=='.',1)-1) );
if frame >= 82 && frame <= 118
I{frame} = imread(fullfile(path,file));
end
end
Now you have a cell-array where the elements I{82} through to I{118} will contain your loaded images.
  1 Comment
Geoff
Geoff on 14 Mar 2012
Note, edited original post. Had not noticed your assumption about the files list indices being the same as the actual frame numbers.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!