-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_testing_data.m
More file actions
69 lines (48 loc) · 1.48 KB
/
create_testing_data.m
File metadata and controls
69 lines (48 loc) · 1.48 KB
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 [data, D, b] = create_testing_data(dataNum,hogParam)
%dataNum is the number of face images
%hogParam is the number of hog pixels to block
%preserve 5:1 ratio of nonFace to Face
sampNum = 5*dataNum;
%HoG Parameters
hogDim = 31;
%Width of image (assuming square)
imgDim = 28;
%creating dataset
data = zeros(hogDim*(imgDim/hogParam)^2+1,dataNum+sampNum);
%setting path
fPath = [pwd '/images/'];
%%%%PART 1: IMPORTING FACE IMAGES
%use dataNum in loop to select all images
for x=(1:dataNum)
%Importing the picture
img = imread([fPath 'pic' num2str(20000+ x) '.ppm']);
%img = rgb2gray(img);
%Resize the image to 28 x 28 x 3
img = imresize(img, [imgDim, imgDim]);
%Converting to greyscale
img = rgb2gray(img);
%Vectorizing and normalizing the imgture
img = vec_norm(img,hogParam);
%img_blue = vec_norm(img_blue);
%img_green = vec_norm(img_green);
%Adding '1' as the classifier label
img = [img; 1];
%img = [img_red; img_blue; img_green; 1]';
%Adding to data
data(:,x) = img;
end
%%%%PART 2: GENERATING NON-FACE IMAGES
%for x=(1:imgNum)
%Generating image samples
df = sampleimages(sampNum, 28, hogParam, fPath);
%Adding '-1' as the classifier label
df = [df; -ones(1,sampNum)];
%Adding to data
colIndex = 1+dataNum;
data(:,colIndex:colIndex+sampNum-1) = df;
%end
%add bias term
data = [ones(1,size(data,2)); data];
D = data(1:(end-1),:);
b = data(end,:);
end