Functions | |
static cpl_table * | trace_order (const cpl_table *ordertable, int order, const cpl_image *inputimage, const cpl_image *noise, const cpl_binary *image_bad, int TRACESTEP, double MAXGAP) |
Trace a single order line. | |
static int | count_orders (const cpl_table *tracetable) |
Count orders in trace table. | |
static double | fit_order_linear (cpl_table *singletrace, int order, double KAPPA, double *slope) |
Make a linear fit of an order trace. | |
static int | get_xcenter (int nx, int ny, cpl_table *ordertable, int row) |
Calculate the x-center of an order. | |
static int | get_ycenter (int nx, int ny, cpl_table *ordertable, int row) |
Calculate the y-center of an order. | |
static int | get_orderlength (int nx, int ny, cpl_table *ordertable, int row) |
Calculate the length of an order line. | |
static double | estimate_threshold (const cpl_image *inputimage, const cpl_image *noise, cpl_table *ordertable, int row, double relative_threshold) |
Calculate threshold for order tracing algorithm. | |
static bool | find_centroid (const cpl_image *inputimage, const cpl_image *noise, const cpl_binary *image_bad, double threshold, int spacing, int x, double *yguess, double *dY) |
Find order line centroid. | |
cpl_table * | uves_locate_orders (const cpl_image *inputimage, const cpl_image *noise, cpl_table *ordertable, int TRACESTEP, double MINTHRESH, double MAXGAP, double MAXRMS, int *DEFPOL1, int *DEFPOL2, double KAPPA, polynomial **bivariate_fit, int *orders_traced) |
Trace all orders. | |
static cpl_table * | detect_lines (cpl_image *htrans, int minintersept, const cpl_image *inputimage, int NORDERS, bool norders_is_guess, int SAMPLEWIDTH, double PTHRES, double MINSLOPE, double MAXSLOPE, int SLOPERES, bool consecutive) |
Detect order lines from the Hough image. | |
static cpl_error_code | delete_peak (cpl_image *htrans, int minintersept, int hxmax, int hymax, int SPACING, int imagewidth, int SAMPLEWIDTH, double MINSLOPE, double MAXSLOPE, int SLOPERES) |
Delete peak in Hough image. | |
static int | firsttrace (int nx, int SAMPLEWIDTH) |
Get the first trace column. | |
static int | calculate_spacing (const cpl_image *image, int x) |
Estimate spacing of order lines. | |
static double | autocorr (const cpl_image *image, const int x, const int shift) |
Calculate auto-correlation function of image column. | |
static cpl_error_code | update_max (const cpl_image *htrans, int *xmax, int *ymax, int SPACING, int imagewidth, int SAMPLEWIDTH, double MINSLOPE, double MAXSLOPE, int SLOPERES) |
Improve position of a peak in the Hough image. | |
cpl_table * | uves_hough (const cpl_image *image, int ymin, int ymax, int NORDERS, bool norders_is_guess, int SAMPLEWIDTH, double PTHRES, double MINSLOPE, double MAXSLOPE, int SLOPERES, bool consecutive, cpl_image **htrans, cpl_image **htrans_original) |
Compute Hough transform and detect lines. | |
cpl_error_code | uves_draw_orders (const cpl_table *ordertable, cpl_image *image) |
Draw detected order lines. |
This recipe determines the echelle order locations. See man-page for details.
static cpl_table * trace_order | ( | const cpl_table * | ordertable, | |
int | order, | |||
const cpl_image * | inputimage, | |||
const cpl_image * | noise, | |||
const cpl_binary * | image_bad, | |||
int | TRACESTEP, | |||
double | MAXGAP | |||
) | [static] |
Trace a single order line.
ordertable | Basic order table | |
order | (Relative) number of order to trace | |
inputimage | The input image | |
image_bad | image bad pixel map | |
noise | Noise of input image | |
TRACESTEP | The step size (i.e. x-increment) used when tracing | |
MAXGAP | The maximum gap length to jump (in units of image width) |
The order is traced in both directions starting from the center of the order (which is inferred from the slopes and intersepts read from the provided ordertable).
The order line is sampled at x-positions seperated by the parameter TRACESTEP. At each x-position, the y-centroid of the order is calculated. The trace stops if the intensity of the order line is below a certain threshold value in a range determined by the parameter MAXGAP.
The order is traced as far as possible using the lowest threshold value.
The returned table contains three columns, 'X', 'Y' (describing the trace of the order) and 'dY' (uncertainty of 'Y').
Definition at line 1127 of file uves_orderpos_follow.c.
References check, find_centroid(), uves_max_int(), uves_min_int(), uves_msg_debug, and xcenter().
Referenced by uves_locate_orders().
static int count_orders | ( | const cpl_table * | tracetable | ) | [static] |
Count orders in trace table.
tracetable | The order trace table |
/*/ /*----------------------------------------------------------------------------
Definition at line 948 of file uves_orderpos_follow.c.
References passure.
Referenced by uves_locate_orders().
static double fit_order_linear | ( | cpl_table * | singletrace, | |
int | order, | |||
double | KAPPA, | |||
double * | slope | |||
) | [static] |
Make a linear fit of an order trace.
singletrace | Order table containing a single order | |
order | (Relative) number of the order to fit (used only for messaging) | |
KAPPA | Value used for kappa-sigma clipping | |
slope | (output) from linear fit |
The function fits a straight line to the specified order and returns the RMS error of the fit. The columns 'Polynomial fit', 'Residual_Square' and 'OrderRMS' (containing the RMS at every row) are added to the table.
Definition at line 992 of file uves_orderpos_follow.c.
References check, passure, uves_max_int(), uves_msg_debug, uves_polynomial_delete(), uves_polynomial_evaluate_1d(), uves_polynomial_get_coeff_1d(), and uves_polynomial_regression_1d().
Referenced by uves_locate_orders().
static int get_xcenter | ( | int | nx, | |
int | ny, | |||
cpl_table * | ordertable, | |||
int | row | |||
) | [static] |
Calculate the x-center of an order.
nx | Width of input image | |
ny | Height of input image | |
ordertable | Basic order table | |
row | Row of order table to use |
Note that the line center is different from nx / 2, if the order line crosses the upper or low boundary of the image.
Definition at line 1374 of file uves_orderpos_follow.c.
References check, and uves_round_double().
Referenced by get_ycenter(), and uves_locate_orders().
static int get_ycenter | ( | int | nx, | |
int | ny, | |||
cpl_table * | ordertable, | |||
int | row | |||
) | [static] |
Calculate the y-center of an order.
nx | Width of input image | |
ny | Height of input image | |
ordertable | Basic order table | |
row | Row of order table to use |
See get_xcenter()
.
Definition at line 1426 of file uves_orderpos_follow.c.
References check, get_xcenter(), and uves_round_double().
Referenced by uves_locate_orders().
static int get_orderlength | ( | int | nx, | |
int | ny, | |||
cpl_table * | ordertable, | |||
int | row | |||
) | [static] |
Calculate the length of an order line.
nx | Width of input image | |
ny | Height of input image | |
ordertable | Basic order table | |
row | Row of order table to use |
The function returns (x1 - x0) where x1 and x0 are the x-coordinates of the line's endpoints.
Definition at line 1325 of file uves_orderpos_follow.c.
References check, and uves_round_double().
Referenced by uves_locate_orders().
static double estimate_threshold | ( | const cpl_image * | inputimage, | |
const cpl_image * | noise, | |||
cpl_table * | ordertable, | |||
int | row, | |||
double | relative_threshold | |||
) | [static] |
Calculate threshold for order tracing algorithm.
inputimage | The input image | |
noise | Noise of input image | |
ordertable | Basic order table | |
row | Row of order table to use | |
relative_threshold | Parameter defining the threshold to calculate (see text) |
This function calculates the threshold levels used by the order tracing algorithm. The threshold computed is min + relative_threshold * (max - min), where min and max are the minimum and maximum pixel values at the center column of the order. The threshold is always above the noise level.
Definition at line 1459 of file uves_orderpos_follow.c.
References check, passure, uves_max_double(), uves_max_int(), uves_min_int(), uves_msg_debug, and uves_round_double().
Referenced by uves_locate_orders().
static bool find_centroid | ( | const cpl_image * | inputimage, | |
const cpl_image * | noise, | |||
const cpl_binary * | image_bad, | |||
double | threshold, | |||
int | spacing, | |||
int | x, | |||
double * | yguess, | |||
double * | dY | |||
) | [static] |
Find order line centroid.
inputimage | The input image | |
noise | Noise of input image | |
image_bad | Image bad pixel map | |
threshold | Detection threshold | |
spacing | Approximate distance between orders (near this order) | |
x | Find centroid in this column | |
yguess | Guess location of centroid, will be updated with centroid location | |
dY | The uncertainty (which is 'returned') associated with yguess. If this (positive number) cannot be calculated, the variable is set to -1. |
The function calculates the centroid of the vertical strip containing yguess.
All pixels above half peak maximum contribute to the centroid calculation, and the centroid position is refined by making a gaussian fit. Additionally, the function returns true, if the peak intensity is more than 10 sigma, where sigma is the RMS error of the gaussian fit.
Definition at line 1600 of file uves_orderpos_follow.c.
References passure, uves_error_reset, uves_gauss(), uves_gauss_derivative(), uves_max_int(), uves_min_int(), uves_msg_debug, and uves_round_double().
Referenced by trace_order().
cpl_table* uves_locate_orders | ( | const cpl_image * | inputimage, | |
const cpl_image * | noise, | |||
cpl_table * | ordertable, | |||
int | TRACESTEP, | |||
double | MINTHRESH, | |||
double | MAXGAP, | |||
double | MAXRMS, | |||
int * | DEFPOL1, | |||
int * | DEFPOL2, | |||
double | KAPPA, | |||
polynomial ** | bivariate_fit, | |||
int * | orders_traced | |||
) |
Trace all orders.
inputimage | The input echelle image | |
noise | Noise of input image | |
ordertable | The basic order table (one row pr. order) | |
TRACESTEP | See trace_order() | |
MINTHRESH | See trace_order() | |
MAXGAP | See trace_order() | |
MAXRMS | Individual orders are rejected if RMS of a linear fit of the order is larger than MAXRMS * mRMS, where mRMS is the median of all order's RMSs. | |
DEFPOL1 | Degree of global fit (as function of x) If negative, will be set to actual degree used | |
DEFPOL2 | Degree of global fit (as function of order number) If negative, will be set to actual degree used | |
KAPPA | Kappa used for kappa-sigma clipping of linear fits and final global fit | |
bivariate_fit | (output) The global fit of order positions | |
orders_traced | (output) Number of orders detected |
This function creates the order trace table starting from the basic ordertable which contains the (guess) order line slopes and intersepts.
trace_order()
and estimate_threshold()
.Definition at line 250 of file uves_orderpos_follow.c.
References assure_nomsg, check, check_nomsg, count_orders(), estimate_threshold(), fit_order_linear(), get_orderlength(), get_xcenter(), get_ycenter(), passure, trace_order(), uves_error_reset, uves_max_double(), uves_msg, uves_msg_debug, uves_msg_low, uves_msg_warning, uves_polynomial_delete(), and uves_polynomial_regression_2d().
static cpl_table * detect_lines | ( | cpl_image * | htrans, | |
int | minintersept, | |||
const cpl_image * | inputimage, | |||
int | NORDERS, | |||
bool | norders_is_guess, | |||
int | SAMPLEWIDTH, | |||
double | PTHRES, | |||
double | MINSLOPE, | |||
double | MAXSLOPE, | |||
int | SLOPERES, | |||
bool | consecutive | |||
) | [static] |
Detect order lines from the Hough image.
htrans | The Hough transform image (detected features will be deleted) | |
minintersept | Minimum intersept represented in Hough image | |
inputimage | The raw image | |
NORDERS | The number of orders to detect | |
norders_is_guess | Flag indicating if we are allowed detect fewer orders than specified by NORDERS. | |
SAMPLEWIDTH | The seperation of sample traces in the raw image | |
PTHRES | If NORDERS is zero, or if norders_is_guess is true, this is the threshold used for peak detection (detection stops when intensity drops to below PTHRES * (previous intensity)) | |
MINSLOPE | Minimum line slope to search for | |
MAXSLOPE | Maximum line slope to search for | |
SLOPERES | Width of Hough image | |
consecutive | If true, orders are not assumed to be consecutive |
This function locates the peaks in the input Hough image. After detecting a peak, the peak itself and the area around it are deleted to avoid several detections of the same feature (see delete_peak()
).
The peak locations are initially defined as the local maximum points but are refined by calculating the centroid of the local area around the maximum (see update_max()
).
The number of order lines to detect is specified by the parameter NORDERS. If this parameter is set to zero, the function will detect lines until the intensity of the next candidate drops to below PTHRES times the dimmest line (PTHRES must be between 0 and 1; if norders_is_guess is false, the parameter PTHRES is ignored).
An important parameter for the peak removal to work is the (approximate) interorder spacing. This parameter is estimated as the raw image height divided by the predicted number of orders (NORDERS). In automatic mode it is estimated as the first minimum of the auto-correlation function along the column in the Hough image containing the global maximum. Note that these methods assume that the inter order spacing does not vary too much as function of order number.
The results of the detection are written to the returned table in the columns 'Slope' (slope of order), 'Intersept' (y-intersept of order) and 'Spacing' (appropriate interorder distance at this order). The table is sorted according to 'Intersept'. The column 'Order' is a label of the order number starting from 1.
Definition at line 395 of file uves_orderpos_hough.c.
References calculate_spacing(), check, check_nomsg, delete_peak(), passure, update_max(), uves_msg, uves_msg_debug, uves_msg_warning, and uves_round_double().
Referenced by uves_hough().
static cpl_error_code delete_peak | ( | cpl_image * | htrans, | |
int | minintersept, | |||
int | hxmax, | |||
int | hymax, | |||
int | SPACING, | |||
int | imagewidth, | |||
int | SAMPLEWIDTH, | |||
double | MINSLOPE, | |||
double | MAXSLOPE, | |||
int | SLOPERES | |||
) | [static] |
Delete peak in Hough image.
htrans | The Hough transform | |
minintersept | The minimum intersept represented in Hough space | |
hxmax | X-position of peak in Hough space | |
hymax | Y-position of peak in Hough space | |
SPACING | Spacing of order lines | |
imagewidth | Width of raw image | |
SAMPLEWIDTH | Width between traces on raw image | |
MINSLOPE | Minimum line slope to search for | |
MAXSLOPE | Maximum line slope to search for | |
SLOPERES | Width of Hough image |
This function deletes a (previously detected) peak in Hough space, and the butterfly shaped area around the peak.
The peak location (in Hough space) is mapped to a line in the input image (using the inverse Hough transformation). The Hough transform of this (one-dimensional) line is a (two-dimensional) butterfly-shaped area, which is then removed. See code for details.
Definition at line 963 of file uves_orderpos_hough.c.
References check, and firsttrace().
Referenced by detect_lines().
static int firsttrace | ( | int | nx, | |
int | SAMPLEWIDTH | |||
) | [static] |
Get the first trace column.
nx | Width of raw image | |
SAMPLEWIDTH | Separation between traces in raw image |
The function returns the location of the first trace column of the raw image. The location is defined smallest value greater than 0 of (nx / 2 - N * SAMPLEWIDTH), where N is an integer. This ensures that there is always a sample column at nx/2.
Definition at line 927 of file uves_orderpos_hough.c.
Referenced by delete_peak(), and uves_hough().
static int calculate_spacing | ( | const cpl_image * | image, | |
int | x | |||
) | [static] |
Estimate spacing of order lines.
image | The Hough transform | |
x | The column to look at |
The function estimates the interorder spacing as two times the first minimum point of the auto-correlation function along the column at x in the Hough image.
Definition at line 834 of file uves_orderpos_hough.c.
References autocorr, check, and uves_msg_debug.
Referenced by detect_lines().
static double autocorr | ( | const cpl_image * | image, | |
const int | x, | |||
const int | shift | |||
) | [static] |
Calculate auto-correlation function of image column.
image | The image | |
x | The column to look at | |
shift | Where to evaluate the auto-correlation function |
The function returns image(x, y) * image(x, y + shift)) The average is over y-values ranging from 1 to ny - shift (both inclusive).
Definition at line 872 of file uves_orderpos_hough.c.
static cpl_error_code update_max | ( | const cpl_image * | htrans, | |
int * | xmax, | |||
int * | ymax, | |||
int | SPACING, | |||
int | imagewidth, | |||
int | SAMPLEWIDTH, | |||
double | MINSLOPE, | |||
double | MAXSLOPE, | |||
int | SLOPERES | |||
) | [static] |
Improve position of a peak in the Hough image.
htrans | The Hough transform | |
xmax | Peak x-position which will be updated | |
ymax | Peak Y-position which will be updated | |
SPACING | Spacing of order lines | |
imagewidth | Width of raw image | |
SAMPLEWIDTH | Separation between traces in raw image | |
MINSLOPE | Minimum line slope to search for | |
MAXSLOPE | Maximum line slope to search for | |
SLOPERES | Width of Hough image |
This function improves a peak position (from the max. pixel value) to the center of mass of a line passing through the middle of the 'butterfly wings' in hough space. The slope of this line in Hough space is ( -(width of input image) / 2 ).
Only pixels with values above ( (1 - 0.5 / NOT) * peak_value ) contribute to the calculation of the centroid. (Here NOT is the number of sample traces in the input image, and peak_value is the pixel value of the detected maximum.)
Definition at line 753 of file uves_orderpos_hough.c.
References uves_msg_debug, and uves_round_double().
Referenced by detect_lines().
cpl_table* uves_hough | ( | const cpl_image * | image, | |
int | ymin, | |||
int | ymax, | |||
int | NORDERS, | |||
bool | norders_is_guess, | |||
int | SAMPLEWIDTH, | |||
double | PTHRES, | |||
double | MINSLOPE, | |||
double | MAXSLOPE, | |||
int | SLOPERES, | |||
bool | consecutive, | |||
cpl_image ** | htrans, | |||
cpl_image ** | htrans_original | |||
) |
Compute Hough transform and detect lines.
image | Input image | |
ymin | First image row to consider (inclusive, FITS convention) | |
ymax | Last image row to consider (inclusive, FITS convention) | |
NORDERS | The number of orders to detect, or zero | |
norders_is_guess | Flag indicating if we are allowed detect fewer orders than specified by NORDERS. | |
SAMPLEWIDTH | The seperation of sample traces in input image | |
PTHRES | In automatic mode, the ratio between the dimmest and next-dimmest line | |
MINSLOPE | Minimum line slope | |
MAXSLOPE | Maximum line slope | |
SLOPERES | Width of Hough image (number of slopes represented) | |
consecutive | If true, orders are assumed to be consecutive | |
htrans | (output) computed Hough transform with peaks deleted | |
htrans_original | (output) computed Hough transform (returned) |
detect_lines()
for details )This function computes the Hough transform of the image image. The input image is traced along vertical lines seperated by SAMPLEWIDTH.
See also detect_lines()
.
Possible order line slopes range from MINSLOPE to MAXSLOPE . The function assumes that all slopes are positive and small. To detect lines with slopes larger than 0.3 - 0.5 or so, the algorithm should be changed to use polar (i.e. rotation invariant) coordinates in Hough space.
Definition at line 191 of file uves_orderpos_hough.c.
References assure_nomsg, check, check_nomsg, detect_lines(), firsttrace(), passure, uves_msg, uves_msg_debug, uves_msg_warning, and uves_round_double().
cpl_error_code uves_draw_orders | ( | const cpl_table * | ordertable, | |
cpl_image * | image | |||
) |
Draw detected order lines.
ordertable | The order table | |
image | The image to draw on |
This function draws on the input image the lines listed in the provided order table. The intersept and slope of the lines are read from the order table.
Definition at line 1015 of file uves_orderpos_hough.c.
References check, passure, and uves_round_double().
static double autocorr |
Calculate auto-correlation function of image column.
image | The image | |
x | The column to look at | |
shift | Where to evaluate the auto-correlation function |
The function returns image(x, y) * image(x, y + shift)) The average is over y-values ranging from 1 to ny - shift (both inclusive).
Definition at line 111 of file irplib_detmon_lg.c.
Referenced by calculate_spacing().