Compilerbau: Beispiele für wavelet-Transformationen, Gamma-Test und Bildergallerie |
|
1------------------------------------------------------------
2--
3-- simple wavelet transformations
4--
5
6------------------------------------------------------------
7--
8-- wavelet picture combinations
9
10function meanAndDiff(pl : list of picture)
11 : list of picture
12
13 [ pl[0] + pl[1]
14 , pl[0] - pl[1]
15 ]
16;
17
18function inverseMeanAndDiff(pl : list of picture)
19 : list of picture
20
21 [ pl[0].inverseDiff(pl[1])
22 , pl[0].inverseMean(pl[1])
23 ]
24;
25
26function meanAndDiff4(pl : list of picture)
27 : list of picture
28
29 begin
30 var
31 p0pp1, p2pp3, p0mp1, p2mp3 : picture
32 := pl[0] + pl[1]
33 , pl[2] + pl[3]
34 , pl[0] - pl[1]
35 , pl[2] - pl[3]
36
37 ; return
38 [ p0pp1 + p2pp3, p0mp1 + p2mp3
39 , p0pp1 - p2pp3, p0mp1 - p2mp3
40 ]
41 end
42;
43
44------------------------------------------------------------
45--
46-- partition pictures
47
48function partitionSquare(p : picture) : list of picture
49 begin
50 var pl : list of picture
51 := p.partitionHorizontal(2)
52
53 ; return pl[0].partitionVertical(2)
54 + pl[1].partitionVertical(2)
55 end
56;
57
58------------------------------------------------------------
59--
60-- paste pictures
61
62function pasteVertical(pl : list of picture) : picture
63 sideBySide(pl[0],pl[1])
64;
65
66function pasteHorizontal(pl : list of picture) : picture
67 above(pl[0],pl[1])
68;
69
70function pasteSquare(pl : list of picture) : picture
71 above(sideBySide(pl[0], pl[1])
72 ,sideBySide(pl[2], pl[3])
73 )
74;
75
76------------------------------------------------------------
77--
78-- wavelet transformations
79
80function waveHorizontal1Step(p : picture) : picture
81 p.partitionHorizontal(2)
82 .meanAndDiff
83 .pasteHorizontal
84;
85
86function waveHorizontalHead(pl : list of picture)
87 : list of picture
88
89 pl.tail
90 .cons(pl.head.waveHorizontalRecursive)
91;
92
93function waveHorizontalRecursive(p : picture) : picture
94 if p.height <= 1
95 then
96 p
97 else
98 p.partitionHorizontal(2)
99 .meanAndDiff
100 .waveHorizontalHead
101 .pasteHorizontal
102;
103
104function inverseWaveHorizontal1Step(p : picture) : picture
105 begin
106 var pl : list of picture
107 := p.splitHorizontal(2)
108 .inverseMeanAndDiff
109 ; return pl[0].mergeHorizontal(pl[1])
110 end
111;
112
113function inverseWaveHorizontalHead(pl : list of picture)
114 : list of picture
115
116 pl.tail
117 .cons(pl.head.inverseWaveHorizontalRecursive)
118;
119
120function inverseWaveHorizontalRecursive(p : picture) : picture
121 if p.height <= 1
122 then
123 p
124 else
125 begin
126 var pl : list of picture
127 := p.splitHorizontal(2)
128 .inverseWaveHorizontalHead
129 .inverseMeanAndDiff
130 ; return pl[0].mergeHorizontal(pl[1])
131 end
132;
133
134------------------------------------------------------------
135
136function waveVertical1Step(p : picture) : picture
137 p.partitionVertical(2)
138 .meanAndDiff
139 .pasteVertical
140;
141
142function waveVerticalHead(pl : list of picture) : list of picture
143 pl.tail
144 .cons(pl.head.waveVerticalRecursive)
145;
146
147function waveVerticalRecursive(p : picture) : picture
148 if p.width <= 1
149 then
150 p
151 else
152 p.partitionVertical(2)
153 .meanAndDiff
154 .waveVerticalHead
155 .pasteVertical
156;
157
158------------------------------------------------------------
159
160function waveSquare1Step(p : picture) : picture
161 p.partitionSquare
162 .meanAndDiff4
163 .pasteSquare
164;
165
166function waveSquareHead(pl : list of picture) : list of picture
167 pl.tail
168 .cons(pl.head.waveSquareRecursive)
169;
170
171function waveSquareRecursive(p : picture) : picture
172 if p.width <= 1
173 or
174 p.height <= 1
175 then
176 p
177 else
178 p.partitionSquare
179 .meanAndDiff4
180 .waveSquareHead
181 .pasteSquare
182;
183
184------------------------------------------------------------
185
186function storePic( p : picture
187 ; n : string
188 ) : picture
189 begin
190 store(p,n)
191 ; return p
192 end
193;
194
195------------------------------------------------------------
196--
197-- the main program
198
199begin
200 var fn : string
201 := getArgs().head
202
203 ; var p : picture
204 := load(fn)
205
206 ; writeln("1 step horizontal wavelet transformation")
207 ; p.waveHorizontal1Step
208 .storePic(fn + "-wave.H1")
209 .inverseWaveHorizontal1Step
210 .store(fn + "-wave.H1.inverse")
211
212 ; writeln("recursive horizontal wavelet transformation")
213 ; p.waveHorizontalRecursive
214 .storePic(fn + "-wave.HR")
215 .inverseWaveHorizontalRecursive
216 .store(fn + "-wave.HR.inverse")
217
218 ; writeln("1 step vertical wavelet transformation")
219 ; p.waveVertical1Step
220 .store(fn + "-wave.V1")
221
222 ; writeln("recursive vertical wavelet transformation")
223 ; p.waveVerticalRecursive
224 .store(fn + "-wave.VR")
225
226 ; writeln("1 step symmetric wavelet transformation")
227 ; p.waveSquare1Step
228 .store(fn + "-wave.S1")
229
230 ; writeln("recursive symmetric wavelet transformation")
231 ; p.waveSquareRecursive
232 .store(fn + "-wave.SR")
233end
234
235------------------------------------------------------------
236
|
1------------------------------------------------------------
2--
3-- test picture for gamma correction of displays
4--
5------------------------------------------------------------
6
7begin
8 var w,b,r,s : picture
9 := white(1,1), black(1,1), black(1,1), black(1,1)
10
11 ; var width, height, steps : int
12 := 50, 300, 16
13
14 ; var bw : picture
15 := w.sideBySide(b)
16 .above(b.sideBySide(w))
17 .replicate(width div 2, width div 2)
18
19 ; var i : int := 1
20 ; while i <= steps do
21 r,i := r.sideBySide(grey(i / (1.0 * steps),1,1)),i+1
22 endwhile
23
24 ; s := w.scale(width * (steps + 1), 50)
25 .above(r.scale(width,height))
26 .above(bw.replicate(steps + 1, 1))
27 .above(r.scale(width,height).flipVertical)
28 .above(b.scale(width * (steps + 1), width))
29
30 ; s.store("gamma-test")
31end
32
33------------------------------------------------------------
34
35
36
|
Letzte Änderung: 05.01.2015 | © Prof. Dr. Uwe Schmidt |