-
Notifications
You must be signed in to change notification settings - Fork 0
/
getImageBatch.m
77 lines (62 loc) · 1.8 KB
/
getImageBatch.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
71
72
73
74
75
76
77
% GETIMAGEBATCH Load and jitter a batch of images
% input:
% imagePaths: a cell array of images' path
% varargin: setting
% output:
% a 4 dims array that is images data
function data = getImageBatch(imagePaths, varargin)
opts.useGpu = false ;
opts.prefetch = false ;
opts.numThreads = 1 ;
opts.imageSize = [227, 227] ;
opts.cropSize = 227 / 256 ;
opts.keepAspect = true ;
opts.subtractAverage = [] ;
opts.jitterFlip = false ;
opts.jitterLocation = false ;
opts.jitterAspect = 1 ;
opts.jitterScale = 1 ;
opts.jitterBrightness = 0 ;
opts.jitterContrast = 0 ;
opts.jitterSaturation = 0 ;
opts = vl_argparse(opts, varargin);
% the whole process is crop firstly and then resize the image according to
% the imageSize
% cropping is determined by the CropAnisotropy and cropSize
% CropAnisotropy is equal to WCrop/HCrop
args{1} = {imagePaths, ...
'NumThreads', opts.numThreads, ...
'Pack', ...
'Interpolation', 'bicubic', ...
'Resize', opts.imageSize(1:2), ...
'CropSize', opts.cropSize * opts.jitterScale, ...
'CropAnisotropy', opts.jitterAspect, ...
'Brightness', opts.jitterBrightness, ...
'Contrast', opts.jitterContrast, ...
'Saturation', opts.jitterSaturation} ;
if ~opts.keepAspect
% Squashign effect
args{end+1} = {'CropAnisotropy', 0} ;
end
if opts.jitterFlip
args{end+1} = {'Flip'} ;
end
if opts.jitterLocation
args{end+1} = {'CropLocation', 'random'} ;
else
args{end+1} = {'CropLocation', 'center'} ;
end
if opts.useGpu
args{end+1} = {'Gpu'} ;
end
if ~isempty(opts.subtractAverage)
args{end+1} = {'SubtractAverage', opts.subtractAverage} ;
end
args = horzcat(args{:}) ;
if opts.prefetch
vl_imreadjpeg(args{:}, 'prefetch') ;
data = [] ;
else
data = vl_imreadjpeg(args{:}) ;
data = data{1} ;
end