fit_curve.h

00001 
00002 
00003 /*---------------------------------------------------------------------------
00004                                     E.S.O.
00005  ----------------------------------------------------------------------------
00006    File name    :   fit_curve.h
00007    Author       :   N. Devillard
00008    Created on   :   July 1998
00009    Language     :   ANSI C
00010                     Part of ECLIPSE library
00011    Description  :   1d and 2d fit related routines
00012  *--------------------------------------------------------------------------*/
00013 
00014 /*
00015 
00016     $Id: fit_curve.h,v 1.1 2003/09/03 12:50:47 amodigli Exp $
00017     $Author: amodigli $
00018     $Date: 2003/09/03 12:50:47 $
00019     $Revision: 1.1 $
00020 
00021 */
00022 
00023 #ifndef _FIT_CURVE_H_
00024 #define _FIT_CURVE_H_
00025 
00026 /*---------------------------------------------------------------------------
00027                                 Includes
00028  ---------------------------------------------------------------------------*/
00029 
00030 #include "matrix.h"
00031 #include "median.h"
00032 #include "ipow.h"
00033 
00034 /* Following definitions are need if compiled out of eclipse */
00035 #ifndef _ECLIPSE_TYPES_H_
00036 #define e_error printf
00037 #include "types.h"
00038 
00039 static int Debug = 0 ;
00040 
00041 #endif
00042 
00043 
00044 /*---------------------------------------------------------------------------
00045                             Function codes
00046  ---------------------------------------------------------------------------*/
00047 
00048 
00049 
00050 
00051 /*---------------------------------------------------------------------------
00052    Function :   fit_1d_poly()
00053    In       :   requested polynomial degree
00054                 a list of pixel positions + number of pixels in the list
00055                 (out) mean squared error, set to NULL if you do not want
00056                 to compute it.
00057    Out      :   newly allocated array containing fit coefficients
00058    Job      :   fit a polynomial to a list of pixel positions
00059    Notice   :
00060                 The fitted polynomial is such that:
00061                 y = c[0] + c[1].x + c[2].x^2 + ... + c[n].x^n
00062                 So requesting a polynomial of degree n will return n+1
00063                 coefficients. Beware that with such polynomials, two
00064                 input points shall never be on the same vertical!
00065  ---------------------------------------------------------------------------*/
00066 
00067 double *
00068 fit_1d_poly(
00069     int         poly_deg,
00070     dpoint  *   list,
00071     int         np,
00072     double  *   mean_squared_error
00073 ) ;
00074 
00075 
00076 
00077 /*---------------------------------------------------------------------------
00078    Function :   fit_surface_polynomial()
00079    In       :   list of pixels, # of pixels in the list.
00080                 character string indicating which coefficients should be
00081                 taken into account, maximum polynomial degree.
00082    Out      :   double * (table of fitted coefficients)
00083                 number of coefficients returned
00084                 mean squared error for the fit.
00085    Job      :   fit a 2d surface with a polynomial in (x,y).
00086    Notice   :   To define which coefficients should be computed, either
00087                 provide NULL for the control string and the maximal
00088                 polynomial degree, or fill up the control string as
00089                 follows:
00090 
00091                 The control string contains (int,int) couples. The first
00092                 integer specifies the degree for X, the second one the
00093                 degree for Y. Couples are given in parentheses, integers
00094                 separated by a comma, with no blanks within the
00095                 parentheses. Couples are separated from other couples by
00096                 one blank character. Example: to compute the fit for an
00097                 equation of type:
00098 
00099                 P(x,y) = c[0] + c[1].x + c[2].x^2 + c[3].x.y
00100 
00101                 You would provide the following control string:
00102 
00103                 "(0,0) (1,0) (2,0) (1,1)"
00104                 (0,0) is degx=0 and degy=0 -> constant term c[0]
00105                 (1,0) is degx=1 and degy=0 -> term in x     c[1]
00106                 (2,0) is degx=2 and degy=0 -> term in x^2   c[2]
00107                 (1,1) is degx=1 and degy=1 -> term in x.y   c[3]
00108 
00109                 The maximal polynomial degree indicates the highest sum
00110                 for X and Y degrees. Example: for poly_deg=3, only the
00111                 following terms can be computed:
00112 
00113                 1       x       x^2     x^3
00114                 y       x.y     x^2.y
00115                 y^2     x.y^2
00116                 y^3
00117 
00118                 If you do not provide any control string, use NULL as
00119                 argument and set the polynomial degree to what you wish,
00120                 all terms satisfying the condition (degx+degy<=polydeg)
00121                 will be taken into account for the fit.
00122                 
00123  ---------------------------------------------------------------------------*/
00124 
00125 double *
00126 fit_surface_polynomial(
00127     /* The surface to fit */
00128     pixel_position  *   surface,
00129     int                 np,
00130 
00131     /* The polynomial to use is defined here */
00132     char            *   control_string,
00133     int                 poly_deg,
00134     int             *   ncoeffs,
00135     double          *   mean_squared_error
00136 ) ;
00137 
00138 
00139 /*---------------------------------------------------------------------------
00140    Function :   buildup_polytab_from_string()
00141    In       :   control string,
00142                 polynomial degree,
00143                 allocated table to fill in for x degrees,
00144                 allocated table to fill in for y degrees,
00145                 -> degx_tab and degy_tab must have allocated at least 
00146                    (1+poly_deg)*(2+poly_deg)/2 integers
00147    Out      :   number of coefficients found
00148    Job      :   translates a control string into a list of polynomial
00149                 degrees for x and y.
00150    Notice   :   returns -1 in case of error.
00151                 A control string is given as:
00152 
00153                 "(int,int) (int,int) [...] (int,int)"
00154 
00155                 each couple (int,int) represents the degree in x and y
00156                 to be computed for the fit. Couples are given in
00157                 parentheses and separated by commas, without any space
00158                 between the parentheses.
00159 
00160                 Couples are separated from each other by any number of
00161                 blank characters (at least one is required).
00162 
00163                 The following is a valid control string:
00164                 "(0,0) (1,2) (2,1) (1,1)"
00165 
00166                 The following are invalid control strings:
00167                 "(0, 0)"        blanks in parentheses
00168                 "( 0 , 0 )"     blanks in parentheses
00169                 "(0,0)(1,2)"    no blank between couples
00170 
00171  ---------------------------------------------------------------------------*/
00172 
00173 int buildup_polytab_from_string(
00174     char    *   s,
00175     int         poly_deg,
00176     int     *   degx_tab,
00177     int     *   degy_tab
00178 );
00179 
00180 
00181 /*---------------------------------------------------------------------------
00182    Function :   fit_slope_robust()
00183    In       :   list of dpoints, # of points in the list
00184    Out      :   pointer to (newly allocated) 3 doubles
00185                 y = c[0] + c[1] * x
00186                 c[2] is the median squared error 
00187    Job      :   fit a slope to a list of points
00188    Notice   :   very robust - up to 50% outliers in input
00189  ---------------------------------------------------------------------------*/
00190 
00191 
00192 
00193 double *
00194 fit_slope_robust(
00195     dpoint  *   list,
00196     int         np
00197 ) ;
00198 
00199 
00200 /*---------------------------------------------------------------------------
00201    Function :   fit_slope()
00202    In       :   list of dpoints, # of points in the list
00203    Out      :   pointer to 3 doubles
00204                 slope is: c[0] + c[1] * x
00205                 c[2] is the average square error
00206    Job      :   fit a slope to a list of points
00207    Notice   :   linear least-squares without any refinement
00208  ---------------------------------------------------------------------------*/
00209 
00210 double *
00211 fit_slope(dpoint * pts, int n);
00212 
00213 
00214 
00215 /*---------------------------------------------------------------------------
00216    Function :   fit_proportional()
00217    In       :   list of dpoints, # of points in the list
00218    Out      :   1 pointer to 2 doubles (NULL if cannot fit slope)
00219                 first double is the fitted slope, second is the average
00220                 squared error.
00221    Job      :   compute a = y/x for all points, return the median 'a'
00222    Notice   :   robustified by the median
00223  ---------------------------------------------------------------------------*/
00224 
00225 double *
00226 fit_proportional(dpoint * pts, int n);
00227 
00228 
00229 
00230 
00231 #endif

Generated on Wed Oct 26 13:08:52 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001