-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocessing.m
79 lines (66 loc) · 2.21 KB
/
preprocessing.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
78
79
function imSets = preprocessing(imOrigin, resize, Angle)
if nargin == 2
Angle = 'test';
end
l = bwlabel(imOrigin);
stats = regionprops(l);
areas = cat(1, stats.Area);
% Eliminating small parts in the image
if length(areas) < 4
index = find(areas == max(areas));
l(l ~= index) = 0;
l(l == index) = 1;
else
sort_a = sort(areas, 'descend');
index = find(areas == sort_a(1));
l(l == index) = 1;
index = find(areas == sort_a(1));
l(l == index) = 1;
l(l ~= 1) = 0;
end
% Eliminating empty lines
temp = delete_empty(medfilt2(l, [3 3]));
if isstr(Angle)
% reshape the image
imSets = reshape(imresize(temp, resize, 'bilinear'), 1, prod(resize));
else
% rotate, reshape, return
len = length(Angle);
if(isempty(find(Angle == 0, 1)))
len = len + 1;
end
imSets = zeros(len, resize(1)*resize(2));
imSets(1, :) = reshape(imresize(temp, resize, 'bilinear'), 1, prod(resize));
rown = 2;
for angle = Angle
if angle ~= 0
temp2 = imrotate(temp, angle, 'bilinear');
temp2 = delete_empty(temp2);
imSets(rown, :) = reshape(imresize(temp2, resize, 'bilinear'), 1, prod(resize));
rown = rown + 1;
end
end
end
% len = length(Angle);
% if(isempty(find(Angle == 0, 1)))
% len = len + 1;
% end
%
% imSets = zeros(len, resize(1)*resize(2));
%
% imSets(1, :) = reshape(imresize(temp, resize, 'bilinear'), 1, prod(resize));
%
% rown = 2;
% for angle = Angle
% if angle ~= 0
% temp2 = imrotate(temp, angle, 'bilinear');
% temp2 = delete_empty(temp2);
% imSets(rown, :) = reshape(imresize(temp2, resize, 'bilinear'), 1, prod(resize));
% rown = rown + 1;
% end
% end
% for i = 1:length(imSets)
% imSets(i) = imresize(imSets(i), resize, 'bilinear');
% end
% temp = imresize(delete_empty(temp), resize, 'bilinear');
end