Merge branch 'master' of https://scm.cri.ensmp.fr/git/Faustine
[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(size, iter) = seq(i, iter, dilating(size));
21 //erosion(size, iter) = seq(i, iter, eroding(size));
22
23 dilation_square(x, y) = serialize : dilating(x) : vectorize(y) : matrix_transpose(y, x) : serialize : dilating(y) : vectorize(x) : matrix_transpose(x, y);
24
25 erosion_square(x, y) = serialize : eroding(x) : vectorize(y) : matrix_transpose(y, x) : serialize : eroding(y) : vectorize(x) : matrix_transpose(x, y);
26
27 cross = _, _ <: !, _, _, !;
28
29 //dilations(x, y, iter) = seq(i, iter, dilation_square(x,y));
30 //erosions(x, y, iter) = seq(i, iter, erosion_square(x,y));
31
32 dilations(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : dilation_square(x, y))~_), (iter - 1)) : rdtable : serialize;
33 erosions(x, y, iter) = _ : vectorize(y) : (iter, ((cross : ((0, 1 : prefix), _, _ : select2) : erosion_square(x, y))~_), (iter - 1)) : rdtable : serialize;
34
35 opening(x, y, iter) = erosions(x, y, iter) : dilations(x, y, iter);
36 closing(x, y, iter) = dilations(x, y, iter) : erosions(x, y, iter);
37
38 threshold(x, n) = _, (n : vectorize(x)) : >;
39 and = *;
40
41 licenceplate(x, y, seuil) = _ <: (opening(x, y, 1), closing(x, y, 1) : threshold(x, seuil), threshold(x, seuil) : and : opening(x, y, 1) : dilations(x, y, 1)), _ : and;
42
43 //process = dilations(8, 8, 3);
44 //process = erosions(8, 8, 3);
45 //process = open(8, 8, 2);
46 //process = close(8, 8, 5);
47 //process = licenceplate(8, 8, 128);
48
49