forked from DiclehanOguzhan/MDO_MEF
-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_images.m
70 lines (61 loc) · 1.66 KB
/
load_images.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
% This procedure loads a sequence of images
%
% Arguments:
% 'path', refers to a directory which contains a sequence of JPEG or PPM
% images
% 'reduce' is an optional parameter that controls downsampling, e.g., reduce = .5
% downsamples all images by a factor of 2.
function I = load_images(path, reduce)
if ~exist('reduce')
reduce = 1;
end
if (reduce > 1 || reduce <= 0)
error('reduce must fulfill: 0 < reduce <= 1');
end
% find all JPEG or PPM files in directory
files = dir(path);
files(1:2)=[];
N = length(files);
if (N == 0)
files = dir([path '/*.png']);
N = length(files);
if (N == 0)
files = dir([path '/*.gif']);
N = length(files);
if (N == 0)
files = dir([path '/*.bmp']);
N = length(files);
if (N == 0)
files = dir([path '/*.jpg']);
N = length(files);
if (N == 0)
error('no files found');
end
end
end
end
end
% allocate memory
sz = size(imread([path '/' files(1).name]));
r = floor(sz(1)*reduce);
c = floor(sz(2)*reduce);
I = zeros(r,c,3,N);
% read all files
for i = 1:N
% load image
filename = [path '/' files(i).name];
im = double(imread(filename));
if (size(im,1) ~= sz(1) || size(im,2) ~= sz(2))
error('images must all have the same size');
end
% optional downsampling step
% optional downsampling step
if (reduce < 1)
im = imresize(im,[r c],'bicubic');
end
if size(im,3)==1
I(:,:,:,i) = cat(3,im,im,im);
else
I(:,:,:,i) = im;
end
end