-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsampleimages.m
72 lines (52 loc) · 1.95 KB
/
sampleimages.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
function X = sampleimages(samples, winsize, hogParam, path)
% gathers patches from the grey-scale images, no preprocessing done yet
%
% INPUT variables:
% samples total number of patches to take
% winsize patch width in pixels
%
% OUTPUT variables:
% X the image patches as column vectors
%IMPORTANT: IMAGE DATA IS SUPPOSED TO BE IN DIRECTORY ./DATA/
%CHANGE THIS ON LINE 34 IF YOU HAVE MOVED THE DATA ELSEWHERE
%----------------------------------------------------------------------
% Gather rectangular image patches
%----------------------------------------------------------------------
% HoG Dimensions
hogDim = 31;
% We have a total of 16 images.
dataNum = 16;
% This is how many patches to take per image
getsample = floor(samples/dataNum);
% Initialize the matrix to hold the patches
%X = zeros(winsize^2,samples);
X = zeros(hogDim * (winsize / hogParam)^2,samples);
sampleNum = 1;
% Setting seed for replicable results
s = rng(23,'twister');
for i=(1:dataNum)
% Even things out (take enough from last image)
if i==dataNum, getsample = samples-sampleNum+1; end
% Load the image. Change the path here if needed.
I = imread([path 'notface' num2str(i) '.jpg']);
% Transform to double precision
I = double(I);
% Select first channel
I = I(:,:,1);
% Normalize to zero mean and unit variance (optional)
%I = I-mean(mean(I));
%I = I/sqrt(mean(mean(I.^2)));
% Sample patches in random locations
sizex = size(I,2);
sizey = size(I,1);
posx = floor(rand(1,getsample)*(sizex-winsize-2))+1;
posy = floor(rand(1,getsample)*(sizey-winsize-1))+1;
for j=1:getsample
%X(:,sampleNum) = reshape( I(posy(1,j):posy(1,j)+winsize-1,posx(1,j):posx(1,j)+winsize-1),[winsize^2 1]);
X(:,sampleNum) = vec_norm( I(posy(1,j):posy(1,j)+winsize-1,posx(1,j):posx(1,j)+winsize-1),hogParam);
sampleNum=sampleNum+1;
end
%for xCol = 1:size(X,2)
% X(:,xCol) = X(:,xCol) / norm(X(:,xCol));
%end
end