-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimiserEachDigit.m
More file actions
executable file
·58 lines (46 loc) · 2.2 KB
/
optimiserEachDigit.m
File metadata and controls
executable file
·58 lines (46 loc) · 2.2 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
function [coordEachDigits] = optimiserEachDigit(coordEachDigits, image, nb_digits, nb_times)
% coordEachDigits(num_ligne, 1, num_fois) %xa
% coordEachDigits(num_ligne, 2, num_fois) %ya
%
% coordEachDigits(num_ligne, 3, num_fois) %xb
% coordEachDigits(num_ligne, 4, num_fois) %yb
% figure('Name','Point image');
% imshow(image);
for num_ligne = 1:nb_digits
for num_fois = 1:nb_times
tmp_digit = image(coordEachDigits(num_ligne, 2, num_fois):coordEachDigits(num_ligne, 4, num_fois),coordEachDigits(num_ligne, 1, num_fois):coordEachDigits(num_ligne, 3, num_fois));
%imshow(tmp_digit);
h_vertical = histo_horizontale(tmp_digit);
%compte le nombre de ligne en parcourant l'histogramme dès qu'il
%rencontre un pic recupere l'abscisse, il en sort puis modifie
%les coordonnee du digit xa, ya et xb, yb.
col = false; %true pendant qu'on est sur le pic
%num de la col
size_im = size(h_vertical);
tmp_y1 = 1;
tmp_y2 = size(h_vertical, 1);
size(tmp_digit);
for i = 1:size_im(1)
if h_vertical(i, 1) > 0 && col == false
col = true;
tmp_y1 = i;
end
if h_vertical(i, 1) == 0 && col == true
tmp_y2 = i - 1;
break;
end
end
%tmp_result = tmp_digit(tmp_y1:tmp_y2,:);
%imshow(tmp_result);
%save(tmp_result,num_ligne,num_fois)
coordEachDigits(num_ligne, 2, num_fois) = coordEachDigits(num_ligne, 2, num_fois) + tmp_y1;%ya
coordEachDigits(num_ligne, 4, num_fois) = coordEachDigits(num_ligne, 4, num_fois) - (size(tmp_digit, 1) - tmp_y2);%yb
% hold on
% plot(coordEachDigits(num_ligne, 1, num_fois), coordEachDigits(num_ligne, 2, num_fois), 'g.');
% plot(coordEachDigits(num_ligne, 3, num_fois), coordEachDigits(num_ligne, 4, num_fois), 'r.');
end
end
end
function [result] = histo_horizontale(I)
result = sum(I < 50, 2);
end