Author Topic: Weights in SurfaceSpline  (Read 7163 times)

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Weights in SurfaceSpline
« on: 2013 December 30 02:30:43 »
I don't know how to use the weight vector in SurfaceSpline. I have tried to follow the very limited documentation but I can not make it work. I don't know if if there is a bug or (much more probable) something I am misunderstanding.

I have written a small test script:
Code: [Select]
function TestSurfaceSpline()
{
   var x=[0, 1, 2, 0, 1, 2, 0, 1, 2];
   var y=[0, 0, 0, 1, 1, 1, 2, 2, 2];
   var z=[0, 0, 0, 0, 1, 0, 0, 0, 0];
   var w=[1, 1, 1, 1, 0.5, 1, 1, 1, 1];

   console.writeln("\nTest without weights:");
   var spline1 = new SurfaceSpline();
   spline1.smoothing = 0.25;
   spline1.order = 2;
   spline1.initialize(new Vector(x), new Vector(y), new Vector(z));
   var val1=spline1.evaluate(new Point(1,1));
   console.writeln("Val1: ", val1);

   console.writeln("\nTest with weights:");
   var spline2 = new SurfaceSpline();
   spline2.smoothing = 0.25;
   spline2.order = 2;
   spline2.initialize(new Vector(x), new Vector(y), new Vector(z), new Vector(w));
   var val2=spline2.evaluate(new Point(1,1));
   console.writeln("Val2: ", val2);
}

TestSurfaceSpline();

The first spline without weights works well. However, the second spline, in which I add the weight vector, fails:
Code: [Select]
Test without weights:
Val1: 0.8039267991984922

Test with weights:
*** Error [000]: C:/Users/Andres/Documents/PCL/test.js, line 20: Error: SurfaceSplineGenerateD(): Low-level API function error
API error code = 69:
Singular matrix

What I am doing wrong?.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Weights in SurfaceSpline
« Reply #1 on: 2014 January 07 01:50:05 »
Hi Andrés,

You have discovered a bug in the PJSR implementation of SurfaceSpline. This bug is now fixed in build 1073 of the PixInsight Core application, which I'm going to release in a few days. The bug only affects data point weights; the rest of SurfaceSpline works correctly. Sorry for the trouble.

On a side note, SurfaceSpline weights allow you to define the statistical weight of each data point. For each data point {xi,yi,zi}, the local smoothness si of the surface spline function is calculated as:

si = S / wi

where S is the global smoothness parameter (corresponding to the SurfaceSpline.smoothing property), and wi is the point's weight. When no weights are specified, all wi=1 by default.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Weights in SurfaceSpline
« Reply #2 on: 2014 January 07 01:58:02 »
Thanks Juan,

I think weighted splines can improve ImageSolver in a significant way. I will test this when you release the fix.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Weights in SurfaceSpline
« Reply #3 on: 2014 January 07 02:03:24 »
Approximating surface splines have improved StarAlignment's distortion correction a lot with just a global smoothness parameter. I also plan on using per-star weights in the next version, based on measurements of centroid determination quality.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/