Add rate_type in interpreter/types.ml.
[Faustine.git] / architecture / morpho.lib
1 import("fft.lib");
2 import("fft2d.lib");
3
4 DILATION_MIN = 0;
5 EROSION_MAX = 255;
6
7 strel_shift_dilation = DILATION_MIN : vectorize(1);
8 strel_shift_erosion = EROSION_MAX : vectorize(1);
9
10 spray_by_three(n) = _ <: par(i, n, ([i], [i+1], [i+2]));
11
12 tri_max = max, _ : max;
13 tri_maxs(n) = par(i, n, tri_max);
14 tri_min = min, _ : min;
15 tri_mins(n) = par(i, n, tri_min);
16
17 dilating(n) = strel_shift_dilation, _, strel_shift_dilation : #, _ : # : spray_by_three(n) : tri_maxs(n) : nconcat(n);
18 eroding(n) = strel_shift_erosion, _, strel_shift_erosion : #, _ : # : spray_by_three(n) : tri_mins(n) : nconcat(n);
19
20 dilation_line(x, y) = serialize : dilating(x) : vectorize(y);
21 erosion_line(x, y) = serialize : eroding(x) : vectorize(y);
22
23 dilation_column(x, y) = matrix_transpose(y, x) : serialize : dilating(y) : vectorize(x) : matrix_transpose(x, y);
24 erosion_column(x, y) = matrix_transpose(y, x) : serialize : eroding(y) : vectorize(x) : matrix_transpose(x, y);
25
26 dilation_square(x, y) = dilation_line(x, y) : dilation_column(x, y);
27 erosion_square(x, y) = erosion_line(x, y) : erosion_column(x, y);
28
29 cross = _, _ <: !, _, _, !;
30
31 dilations_line(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : dilation_line(x, y))~_), (iter - 1)) : rdtable : serialize;
32
33 erosions_line(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : erosion_line(x, y))~_), (iter - 1)) : rdtable : serialize;
34
35 dilations_column(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : dilation_column(x, y))~_), (iter - 1)) : rdtable : serialize;
36
37 erosions_column(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : erosion_column(x, y))~_), (iter - 1)) : rdtable : serialize;
38
39 dilations_square(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : dilation_square(x, y))~_), (iter - 1)) : rdtable : serialize;
40
41 erosions_square(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : erosion_square(x, y))~_), (iter - 1)) : rdtable : serialize;
42
43 opening_line(x, y, iter) = erosions_line(x, y, iter) : dilations_line(x, y, iter);
44 closing_line(x, y, iter) = dilations_line(x, y, iter) : erosions_line(x, y, iter);
45
46 opening_column(x, y, iter) = erosions_column(x, y, iter) : dilations_column(x, y, iter);
47 closing_column(x, y, iter) = dilations_column(x, y, iter) : erosions_column(x, y, iter);
48
49 opening_square(x, y, iter) = erosions_square(x, y, iter) : dilations_square(x, y, iter);
50 closing_square(x, y, iter) = dilations_square(x, y, iter) : erosions_square(x, y, iter);
51
52 and = *;
53 threshold(x, low, high) = _ <: (_, (low : vectorize(x)) : >), (_, (high : vectorize(x)) : <) : and;
54
55 //licenceplate(x, y) = _ <: (opening_line(x, y, 15), closing_line(x, y, 8) : threshold(x, 1, 50), threshold(x, 150, 255) : and : opening_column(x, y, 4) : opening_line(x, y, 4) : dilations_square(x, y, 2)), _ : and;
56
57 licenceplate(x, y, o1, c2, t3, t4, t5, t6, o7, o8, d9) = _ <: (opening_line(x, y, o1), closing_line(x, y, c2) : threshold(x, t3, t4), threshold(x, t5, t6) : and : opening_column(x, y, o7) : opening_line(x, y, o8) : dilations_square(x, y, d9)), _ : and;
58
59 //licenceplate(x, y) = _ <: (opening_line(x, y, 4), closing_line(x, y, 2) : threshold(x, 1, 50), threshold(x, 150, 255) : and : opening_column(x, y, 4) : opening_line(x, y, 4) : dilations_square(x, y, 4)), _ : and;
60
61 //process = dilations_line(8, 8, 3);
62 //process = erosions(8, 8, 3);
63 //process = open(8, 8, 2);
64 //process = close(8, 8, 5);
65 //process = licenceplate(100, 50, 15, 8, 1, 50, 150, 255, 4, 4, 2);
66
67