// derivs2 // // for debugging transforms of derivatives from index to world, in 2D, // using synthetic data of a parabola. The Catmull-Rom can exactly // reconstruct quadratic functions, so this is a good test case. // // Can output image of errors in reconstructed values, or reconstructed // gradients, according to which of (1), (2), (3) is uncommented below. // In all cases, output is processed with: // // unu reshape -i mip.txt -s 3 300 300 | unu quantize -b 8 -min 0 -max 1 -o derivs2.png // // This should produce an *ALL BLACK IMAGE* (modulo a few near-black // pixels due to numerical precision issues) // F: full isotropic resolution image(2)[] Fimg = image ("../data/parab/parab2-150.nrrd"); field#1(2)[] F0 = Fimg ⊛ ctmr; field#2(2)[] F = Fimg ⊛ bspln3; // FX: one fifth as many samples along X image(2)[] FXimg = image ("../data/parab/parab2-x30.nrrd"); field#1(2)[] F0X = FXimg ⊛ ctmr; field#2(2)[] FX = FXimg ⊛ bspln3; // FY: one fifth as many samples along Y image(2)[] FYimg = image ("../data/parab/parab2-y30.nrrd"); field#1(2)[] F0Y = FYimg ⊛ ctmr; field#2(2)[] FY = FYimg ⊛ bspln3; int imgSize = 300; strand sample (int xi, int yi) { real xx = lerp(-50.0, 50.0, 0.0, real(xi), real(imgSize-1)); real yy = lerp(-50.0, 50.0, 0.0, real(yi), real(imgSize-1)); vec2 p = [xx,yy]; real f = xx^2 + yy^2; // analytic parabola function vec2 g = [2.0*xx,2.0*yy]; // analytic gradient tensor[2,2] h = [[2.0,0.0],[0.0,2.0]]; // analytic hessian output vec3 val = [0.0,0.0,0.0]; update { // Uncomment one of the following: // (1) These are the errors in the values (this works fine) // This works fine; here as a sanity check //val = [|F0(p)-f|, |F0X(p)-f|, |F0Y(p)-f|]; // (2) These are magnitudes of the errors in the gradients val = [|∇F(p)-g|, |∇FX(p)-g|, |∇FY(p)-g|]; // (3) Magnitudes of errors in Hessians // The "/50.0" because of greater numerical error in the // second derivatives, which may warrant further study //val = [|∇(∇F)(p)-h|, |∇(∇FX)(p)-h|, |∇(∇FY)(p)-h|]/50.0; stabilize; } } initially [ sample(xi, yi) | yi in 0..(imgSize-1), xi in 0..(imgSize-1) ];
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: stabilize; } } initially [ sample(xi, yi) | yi in 0..(imgSize-1), xi in 0..(imgSize-1) ];