-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.m
69 lines (46 loc) · 1.58 KB
/
preprocess.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
%clear all
handset=[];
y=[];
number=0;
train_start=401;
train_end=497;
%rand_index=randperm(498);
size=28;
rotation_thresh=0;
shift_thresh=0;
for type=1:6
for index=train_start:train_end
%number=number+1;
index_real=rand_index(index+1);
filename=['dataset\',int2str(type),'_\g',int2str(index_real),'.jpg'];
[type index]
origin=imread(filename);
origin=rgb2gray(origin);
level=graythresh(origin);
origin=im2bw(origin,level);%用otsu割图像变成二值图像
%origin=medfilt2(origin);
%imshow(origin)
%对图像进行旋转,进行数据增强
for rotate_order=-1*rotation_thresh:rotation_thresh
tmp=imrotate(origin,rotate_order);
tmp=imresize(tmp,[size,size]);
for shift_x=-1*shift_thresh:shift_thresh
for shift_y=-1*shift_thresh:shift_thresh
se=translate(strel(1),[shift_x,shift_y]);
tmp_shift=imdilate(tmp,se);
%imshow(tmp_shift);
%add the data set
tmp_shift=tmp_shift';
tmp_shift=tmp_shift(:);
handset=[handset,tmp_shift];
%label the data
label=[0,0,0,0,0,0]';
label(type)=1;
y=[y,label];
end
end
end
end
end
handset=handset';
y=y'