Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/lamont/test/lzc2d.diderot
ViewVC logotype

Annotation of /branches/lamont/test/lzc2d.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2081 - (view) (download)

1 : glk 1963 /* lzc2d
2 :    
3 :     Demo of laplacian zero-crossing edges via Newton-Raphson method.
4 :     Initializes positions on a grid, and each update applies one
5 :     step of Newton-Raphson.
6 :    
7 :     Process output with:
8 :    
9 :     unu dice -i posgm.nrrd -a 0 -o ./
10 :     unu jhisto -i {0,1}.nrrd -min 0 0 -max 1 1 -b 600 600 -t float -o count.nrrd
11 :     unu jhisto -i {0,1}.nrrd -w 2.nrrd -min 0 0 -max 1 1 -b 600 600 -t float \
12 :     | unu 2op / - count.nrrd \
13 :     | unu 2op exists - 0 \
14 :     | unu gamma -g 1.4 \
15 :     | unu quantize -b 8 -o lzc2d.png
16 :     rm -f {0,1,2}.nrrd count.nrrd
17 :    
18 :     */
19 :    
20 :    
21 :     int gridSize = 500;
22 :     field#3(2)[] F = bspln5 ⊛ image("../data/ddro-128.nrrd");
23 :     int stepsMax = 30;
24 :     real epsilon = 0.00001;
25 :    
26 :     strand sample (int ui, int vi) {
27 :     output vec3 posgm = [0.0, 0.0, 0.0];
28 :     vec2 pos = [lerp(0.0, 1.0, -0.5, real(ui), real(gridSize)-0.5),
29 :     lerp(0.0, 1.0, -0.5, real(vi), real(gridSize)-0.5)];
30 :     int steps = 0;
31 :     update {
32 :     // We bail if we're no longer inside or taken too many steps.
33 :     if (!inside(pos, F) || steps > stepsMax) {
34 :     die;
35 :     }
36 :     vec2 grad = identity[2]:∇⊗∇⊗∇F(pos); // the gradient of the laplacian
37 :     if (|grad| == 0.0) {
38 :     die;
39 :     }
40 :     vec2 norm = normalize(grad);
41 :     vec2 delta = -(trace(∇⊗∇F(pos))/|grad|)*norm; // Newton-Raphson step
42 :     if (|delta| < epsilon) { // we've converged if step is small enough
43 :     stabilize;
44 :     }
45 :     pos += delta;
46 :     steps += 1;
47 :     }
48 :     stabilize {
49 :     posgm = [pos[0], pos[1], |∇F(pos)|];
50 :     }
51 :     }
52 :    
53 :     initially { sample(ui, vi) | vi in 0..(gridSize-1), ui in 0..(gridSize-1) };

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0