-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadSequence.m
51 lines (44 loc) · 1.42 KB
/
loadSequence.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% VISUAL TRACKING
% ----------------------
% Background Subtraction
% ----------------
% Date: september 2015
% Authors: Desire Sidibe
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ImSeq, NumImages, VIDEO_HEIGHT, VIDEO_WIDTH] = loadSequence(sequence, ext)
%%%%% LOAD THE IMAGES
%=======================
% Give image directory and extension
imPath = sequence; imExt = ext;
% check if directory and files exist
if isdir(imPath) == 0
error('USER ERROR : The image directory does not exist');
end
filearray = dir([imPath filesep '*.' imExt]); % get all files in the directory
NumImages = size(filearray,1); % get the number of images
if NumImages < 0
error('No image in the directory');
end
disp('Loading image files from the video sequence, please be patient...');
% Get image parameters
imgname = [imPath filesep filearray(1).name]; % get image name
I = imread(imgname); % read the 1st image and pick its size
flag = 0;
if size(I,3)>1
I = rgb2gray(I);
flag = 1;
end
VIDEO_WIDTH = size(I,2);
VIDEO_HEIGHT = size(I,1);
ImSeq = zeros(VIDEO_HEIGHT, VIDEO_WIDTH, NumImages);
for i=1:NumImages
imgname = [imPath filesep filearray(i).name]; % get image name
if flag == 1
ImSeq(:,:,i) = rgb2gray(imread(imgname)); % load image
else
ImSeq(:,:,i) = imread(imgname); % load image
end
end
disp(' ... OK!');
end