ifw-odp  2.0.0-alpha
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros
clipm_priv_irplib_flat.c File Reference
#include "clipm_priv_irplib_flat.h"
#include "clipm_compatibility_replacements.h"
#include <math.h>

Macros

#define FITPROP_BIG_SLOPE   1e30
 Compute a=y/x for all given points. More...
 
#define SIGN(a, b)   ((b) >= 0.0 ? fabs(a) : -fabs(a))
 
#define MAX_ITERATE   30
 
cpl_imagelist * clipm_priv_irplib_flat_fit_set (cpl_imagelist *raw, int mode)
 Compute a flat-field out of a set of exposures. More...
 
double * clipm_priv_irplib_flat_fit_slope_robust (double *x, double *y, cpl_size np)
 Fit a slope to a list of points (robust fit). More...
 

Macro Definition Documentation

#define FITPROP_BIG_SLOPE   1e30

Compute a=y/x for all given points.

Parameters
xx coordinates
yy coordinates
npnumber of points
Returns
Pointer to newly allocated array of two doubles.

This function takes in input a list of points supposed all aligned on a slope going through the origin (of equation y=ax). It computes the slope a = y/x for all points, and returns a pointer to two doubles:

{itemize} The median slope. The mean squared error. {itemize}

Returning the median of all slopes makes it very robust to outliers. A more precise method would be to make a histogram of all slopes and take the maximum (i.e. the mode of the distribution). It can be shown that the median approximates the mode quite well for a large number of points.

#define MAX_ITERATE   30
#define SIGN (   a,
 
)    ((b) >= 0.0 ? fabs(a) : -fabs(a))

Function Documentation

cpl_imagelist* clipm_priv_irplib_flat_fit_set ( cpl_imagelist *  raw,
int  mode 
)

Compute a flat-field out of a set of exposures.

Parameters
rawInput image set
mode0 for proportional, 1 for robust fit
Returns
1 newly allocated set of 2 or 3 images

The input is assumed to be a cube containing planes of different intensities (usually increasing or decreasing). Typical inputs are: twilight data sets, halogen lamp, or skies of different airmasses in the thermal regime.

The input image list must be of type float.

In robust mode, the output is a set of 3 images. The first image contains a regression map, i.e. for each pixel position on the detector, a curve is plotted of the pixel intensity in each plane against the median intensity of the plane. A slope is fit, and the gain factor is stored into this first image.

The second image contains the y-intercepts of the slope fit. It is usually good to check it out in case of failures.

The third image contains the sum of squared errors for each fit. The fit is using a robust least-squares criterion rejecting outliers. This is the algorithm to use with big telescopes like the VLT, which collect so much light that objects are actually seen in the twilight sky.

In proportional mode, the output is a set of 2 images. The first image contains a regression map. The second image contains the sum of squared errors for each fit.

double* clipm_priv_irplib_flat_fit_slope_robust ( double *  x,
double *  y,
cpl_size  np 
)

Fit a slope to a list of points (robust fit).

Parameters
xx coordinates
yy coordinates
npnumber of points
Returns
Pointer to newly allocated array of 3 doubles.

The slope to fit has the following kind of equation: y = c[0] + c[1] * x

The returned coefficients are defined as: c[0] is the y-intercept. c[1] is the slope. c[2] is the median squared error of the fit. This is a very robust slope fit. It tolerates up to 50% of outliers in input.