/home/amodigli/releases/xsh/2.1.1/xsh.30433/xshp/xsh/xsh_utils_image.h File Reference

#include <cpl.h>
#include <xsh_error.h>
#include <xsh_data_order.h>

Go to the source code of this file.

Data Structures

struct  _STATS_

Defines

#define TRANSFO_AFFINE   0
#define TRANSFO_DEG2   1
#define TRANSFO_HOMOGRAPHIC   2
#define SHIFT_REJECT_L   2
#define SHIFT_REJECT_R   2
#define SHIFT_REJECT_T   2
#define SHIFT_REJECT_B   2
#define TABSPERPIX   (1000)
#define KERNEL_WIDTH   (2.0)
#define KERNEL_SAMPLES   (1+(int)(TABSPERPIX * KERNEL_WIDTH))
#define TANH_STEEPNESS   (5.0)

Typedefs

typedef float pixelvalue
typedef struct _STATS_ Stats

Functions

cpl_image * xsh_image_compute_geom_corr (cpl_image *in)
 Pixel area geometric trasformation computation.
double * xsh_generate_interpolation_kernel (const char *kernel_type)
cpl_image * xsh_warp_image_generic (cpl_image *image_in, char *kernel_type, cpl_polynomial *poly_u, cpl_polynomial *poly_v)
cpl_image * xsh_image_search_bad_pixels_via_noise (cpl_imagelist *darks, float thresh_sigma_factor, float low_threshold, float high_threshold, int llx, int lly, int urx, int ury)
 search bad pixels
void xsh_pixel_qsort (pixelvalue *pix_arr, int npix)
void xsh_show_interpolation_kernel (char *kernel_name)
double * xsh_generate_tanh_kernel (double steep)
double xsh_fixed_pattern_noise (const cpl_image *master, double convert_ADU, double master_noise)
 Compute fixed pattern noise in flat field.
double xsh_fixed_pattern_noise_bias (const cpl_image *first_raw, const cpl_image *second_raw, double ron)
 Compute fixed pattern noise in bias.
double xsh_image_get_stdev_clean (const cpl_image *image, double *dstdev)
 Get clean (3*sigma clip) empirical stdev of data.
double xsh_image_get_stdev_robust (const cpl_image *image, double cut, double *dstdev)
 Get robust empirical stdev of data.
cpl_error_code xsh_image_warp_polynomial_scale (cpl_image *, const cpl_polynomial *poly_x, const cpl_polynomial *poly_y)
 Compute area change ratio for a 2D polynomial transformation.
cpl_image * xsh_sobel_lx (cpl_image *in)
 Compute X Sobel filter transformation.
cpl_image * xsh_sobel_ly (cpl_image *in)
 Compute Y Sobel filter transformation.
cpl_image * xsh_scharr_x (cpl_image *in)
 Compute X Scharr filter transformation.
cpl_image * xsh_scharr_y (cpl_image *in)
 Compute Y Scharr filter transformation.
cpl_error_code xsh_compute_ron (cpl_frameset *frames, int llx, int lly, int urx, int ury, int nsampl, int hsize, const int reg_id, double *ron, double *ron_err)
 compute ron taking random windows of given size in a given region on 2 frames difference
cpl_image * xsh_image_smooth_fft (cpl_image *inp, const int fx, const int fy)
cpl_image * xsh_image_smooth_median_x (cpl_image *inp, const int r)
cpl_image * xsh_image_smooth_mean_x (cpl_image *inp, const int r)
cpl_image * xsh_image_smooth_median_y (cpl_image *inp, const int r)
cpl_image * xsh_image_smooth_mean_y (cpl_image *inp, const int r)
cpl_image * xsh_image_smooth_median_xy (cpl_image *inp, const int r)
double xsh_image_fit_gaussian_max_pos_x_window (const cpl_image *ima, const int llx, const int urx, const int ypos)
cpl_frame * xsh_cube_qc_trace_window (cpl_frame *frm_cube, xsh_instrument *instrument, const char *prefix, const char *rec_prefix, const int win_min, const int win_max, const int hsize, const int method, const int compute_qc)
 Trace object position in a cube.
cpl_frame * xsh_frame_image_qc_trace_window (cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
 Trace object position in an image.
cpl_frame * xsh_frame_image_ext_qc_trace_window (cpl_frame *frm_ima, xsh_instrument *instrument, const char *suffix, const int hsize, const int method)
 Trace object position in an image.
cpl_error_code xsh_iml_merge_avg (cpl_imagelist **data, cpl_imagelist **mask, const cpl_image *data_ima, const cpl_image *mask_ima, const int mk)
 merge imagelist via average
cpl_error_code xsh_image_mflat_detect_blemishes (cpl_frame *flat_frame, xsh_instrument *instrument)
 Flag blemishes in a flat image.
cpl_error_code xsh_collapse_errs (cpl_image *errs, cpl_imagelist *list, const int mode)
cpl_image * xsh_combine_flats (cpl_image *ima1_in, cpl_image *ima2_in, xsh_order_list *qth_list, xsh_order_list *d2_list, const int xrad, const int yrad)
 Combine flat frames line adjusting illumination level to merge them smoothly.
cpl_error_code xsh_frame_image_save2ext (cpl_frame *frm, const char *name_o, const int ext_i, const int ext_o)
cpl_error_code xsh_frame_image_add_double (cpl_frame *frm, const double value)
cpl_frame * xsh_frame_image_mult_by_fct (cpl_frame *frm, const int fctx, const int fcty)
cpl_frame * xsh_frame_image_div_by_fct (cpl_frame *frm, const int fctx, const int fcty)

Define Documentation

#define KERNEL_SAMPLES   (1+(int)(TABSPERPIX * KERNEL_WIDTH))
#define KERNEL_WIDTH   (2.0)

Definition at line 71 of file xsh_utils_image.h.

Referenced by xsh_generate_interpolation_kernel().

#define SHIFT_REJECT_B   2

Definition at line 62 of file xsh_utils_image.h.

#define SHIFT_REJECT_L   2

Definition at line 59 of file xsh_utils_image.h.

#define SHIFT_REJECT_R   2

Definition at line 60 of file xsh_utils_image.h.

#define SHIFT_REJECT_T   2

Definition at line 61 of file xsh_utils_image.h.

#define TABSPERPIX   (1000)
#define TANH_STEEPNESS   (5.0)

Definition at line 74 of file xsh_utils_image.h.

Referenced by xsh_generate_interpolation_kernel().

#define TRANSFO_AFFINE   0

Definition at line 54 of file xsh_utils_image.h.

#define TRANSFO_DEG2   1

Definition at line 55 of file xsh_utils_image.h.

#define TRANSFO_HOMOGRAPHIC   2

Definition at line 56 of file xsh_utils_image.h.


Typedef Documentation

typedef float pixelvalue

Definition at line 38 of file xsh_utils_image.h.

typedef struct _STATS_ Stats

Function Documentation

cpl_error_code xsh_collapse_errs ( cpl_image *  errs,
cpl_imagelist *  list,
const int  mode 
)

Create an error image from an image list and a "valid pixels" mask

Parameters:
errs [OUTPUT] The errs image result
list error images list to collapse
mode mode qualifier (median or mean stack combination)
Returns:
Pointer to error image

Definition at line 3445 of file xsh_utils_image.c.

References assure, check, M_PI, nx, and ny.

Referenced by xsh_create_master_bias2(), xsh_create_master_dark2(), xsh_find_cosmics(), and xsh_remove_cosmics().

cpl_image* xsh_combine_flats ( cpl_image *  ima1_in,
cpl_image *  ima2_in,
xsh_order_list qth_list,
xsh_order_list d2_list,
const int  xrad,
const int  yrad 
)

Combine flat frames line adjusting illumination level to merge them smoothly.

Parameters:
frm1 1st frame
frm2 2nd frame
otab order table
oref order where to merge
xrad x-radius size
xrad y-radius size
Returns:
CPL_ERROR_NONE if everything is ok

Definition at line 3528 of file xsh_utils_image.c.

References xsh_order_list::absorder_max, xsh_order_list::absorder_min, assure, xsh_order::cenpoly, xsh_order::edglopoly, xsh_order::edguppoly, xsh_order::endy, xsh_order_list::list, llx, lly, xsh_order_list::size, xsh_order::starty, urx, ury, xsh_free_image(), xsh_free_polynomial(), xsh_free_propertylist(), xsh_free_table(), xsh_msg, and xsh_order_list_eval_int().

Referenced by xsh_flat_merge_qth_d2_smooth().

cpl_error_code xsh_compute_ron ( cpl_frameset *  frames,
int  llx,
int  lly,
int  urx,
int  ury,
int  nsampl,
int  hsize,
const int  reg_id,
double *  ron,
double *  ron_err 
)

compute ron taking random windows of given size in a given region on 2 frames difference

Parameters:
frames input frameset
llx image lower left x
lly image lower left y
urx image upper left x
ury image upper left y
nsampl number of sampling window
hsize hal size of (square) window
reg_id parameter switch
ron output ron value
ron_err output error on ron value

Definition at line 1294 of file xsh_utils_image.c.

References check, xsh_error_msg, xsh_free_image(), xsh_free_propertylist(), XSH_PCATG, xsh_pfits_set_qc_ron1(), xsh_pfits_set_qc_ron1_err(), xsh_pfits_set_qc_ron2(), and xsh_pfits_set_qc_ron2_err().

Referenced by xsh_util_ronbias().

cpl_frame* xsh_cube_qc_trace_window ( cpl_frame *  frm_cube,
xsh_instrument instrument,
const char *  suffix,
const char *  rec_prefix,
const int  win_min,
const int  win_max,
const int  hsize,
const int  method,
const int  compute_qc 
)

Trace object position in a cube.

Parameters:
frm_cube The frame whose frame need to be updated
instrument The instrument setting structure
suffix The product filename suffix
rec_prefix The input recipe prefix string value
win_min The win_min value allowed in the search
win_max The win_max value allowed in the search
hsize The half window size used in the object peack final search
method The peack search method 0: Gaussian, 1: centroid
compute_qc Switch to activate QC computation
Returns:
The error code

Definition at line 3109 of file xsh_utils_image.c.

References check, llx, urx, xsh_cube_trace_diff(), xsh_cube_trace_fit(), xsh_frame_product(), xsh_free_imagelist(), xsh_free_propertylist(), xsh_free_table(), xsh_image_fit_gaussian_max_pos_x_window(), xsh_instrument_arm_tostring(), xsh_pfits_get_cdelt3(), xsh_pfits_get_crval3(), and xsh_util_compute_qc_residuals().

Referenced by xsh_build_ifu_cube(), xsh_geom_ifu(), and xsh_util_ifu_build_cube().

double xsh_fixed_pattern_noise ( const cpl_image *  master,
double  convert_ADU,
double  master_noise 
)

Compute fixed pattern noise in flat field.

Parameters:
master master image
convert_ADU factor to convert from master units to ADU
master_noise master noise (ADU) for a shift of zero
Returns:
fixed pattern noise. The master noise is quadratically subtracted

Definition at line 765 of file xsh_utils_image.c.

References assure, xsh_free_image(), and xsh_image_crop().

double xsh_fixed_pattern_noise_bias ( const cpl_image *  first_raw,
const cpl_image *  second_raw,
double  ron 
)

Compute fixed pattern noise in bias.

Parameters:
first_raw First raw bias frame
second_raw Second raw bias frame
ron Read out noise (ADU) for a shift of zero
Returns:
fixed pattern noise. The ron is quadratically subtracted

Definition at line 845 of file xsh_utils_image.c.

References assure, nx, ny, xsh_free_image(), xsh_image_crop(), and xsh_image_get_stdev_robust().

cpl_error_code xsh_frame_image_add_double ( cpl_frame *  frm,
const double  value 
)
cpl_frame* xsh_frame_image_div_by_fct ( cpl_frame *  frm,
const int  fctx,
const int  fcty 
)
cpl_frame* xsh_frame_image_ext_qc_trace_window ( cpl_frame *  frm_ima,
xsh_instrument instrument,
const char *  suffix,
const int  hsize,
const int  method 
)

Trace object position in an image.

Parameters:
frm_ima The image frame where object traces need to be found
instrument The instrument setting structure
suffix The product filename suffix
hsize The half window size used in the object peack final search
method The peack search method 0: Gaussian, 1: centroid
Returns:
The error code

Definition at line 2732 of file xsh_utils_image.c.

References check, xsh_frame_product(), xsh_free_image(), xsh_free_propertylist(), xsh_free_table(), xsh_image_qc_trace_window(), xsh_instrument_arm_tostring(), and xsh_msg.

Referenced by xsh_absorp().

cpl_frame* xsh_frame_image_mult_by_fct ( cpl_frame *  frm,
const int  fctx,
const int  fcty 
)
cpl_frame* xsh_frame_image_qc_trace_window ( cpl_frame *  frm_ima,
xsh_instrument instrument,
const char *  suffix,
const int  hsize,
const int  method 
)

Trace object position in an image.

Parameters:
frm_ima The image frame where object traces need need to be found
instrument The instrument setting structure
suffix The product filename suffix
hsize The half window size used in the object peack final search
method The peack search method 0: Gaussian, 1: centroid
Returns:
The error code

Definition at line 2672 of file xsh_utils_image.c.

References check, xsh_frame_product(), xsh_free_image(), xsh_free_propertylist(), xsh_free_table(), xsh_image_qc_trace_window(), and xsh_instrument_arm_tostring().

Referenced by xsh_absorp().

cpl_error_code xsh_frame_image_save2ext ( cpl_frame *  frm,
const char *  name_o,
const int  ext_i,
const int  ext_o 
)
double* xsh_generate_interpolation_kernel ( const char *  kernel_type  ) 
double* xsh_generate_tanh_kernel ( double  steep  ) 
cpl_image* xsh_image_compute_geom_corr ( cpl_image *  in  ) 

Pixel area geometric trasformation computation.

Parameters:
in input image
Returns:
image containing in each pixel the geometric correction values http://wwwatnf.atnf.csiro.au/computing/software/midas/Hypertext/doc/95NOV/vol2/node19.html

Definition at line 134 of file xsh_utils_image.c.

References assure, check, xsh_compute_geom_corr(), and xsh_free_image().

double xsh_image_fit_gaussian_max_pos_x_window ( const cpl_image *  ima,
const int  llx,
const int  urx,
const int  ypos 
)
double xsh_image_get_stdev_clean ( const cpl_image *  image,
double *  dstdev 
)

Get clean (3*sigma clip) empirical stdev of data.

Parameters:
image image
dstdev (output) error of estimate
Returns:
empirical stdev (scatter around median, not mean)

Definition at line 718 of file xsh_utils_image.c.

References assure, kappa, xsh_free_image(), and xsh_free_mask().

double xsh_image_get_stdev_robust ( const cpl_image *  image,
double  cut,
double *  dstdev 
)

Get robust empirical stdev of data.

Parameters:
image image
cut pixels outside median +- cut are ignored
dstdev (output) error of estimate
Returns:
empirical stdev (scatter around median, not mean)

Definition at line 678 of file xsh_utils_image.c.

References assure, xsh_free_image(), and xsh_free_mask().

Referenced by xsh_fixed_pattern_noise_bias().

cpl_error_code xsh_image_mflat_detect_blemishes ( cpl_frame *  flat_frame,
xsh_instrument instrument 
)

Flag blemishes in a flat image.

Parameters:
flat_frame input image
instrument arm setting
Returns:
output frame or NULL;

Definition at line 3334 of file xsh_utils_image.c.

References xsh_pre::binx, binx, xsh_pre::biny, biny, check, xsh_pre::data, xsh_pre::errs, kappa, xsh_pre::nx, xsh_pre::ny, QFLAG_OTHER_BAD_PIXEL, xsh_pre::qual, XSH_ASSURE_NOT_NULL_MSG, xsh_free_array(), xsh_free_frame(), xsh_free_image(), xsh_free_matrix(), xsh_image_filter_median(), xsh_pre_free(), xsh_pre_load(), and xsh_pre_save().

Referenced by xsh_mflat().

cpl_image* xsh_image_search_bad_pixels_via_noise ( cpl_imagelist *  darks,
float  thresh_sigma_factor,
float  low_threshold,
float  high_threshold,
int  llx,
int  lly,
int  urx,
int  ury 
)

search bad pixels

Parameters:
darks sequence of darks (NDIT = 1) stored in a cube, at least 10 to get good statistics
thresh_sigma_factor factor to determined standard deviation in each pixel to determine the threshold beyond which a pixel is declared as bad.
low_threshold percentage (0...100) of extreme pixel values that is \ not considered for image statistics
high_threshold percentage (0...100) of extreme pixel values that is \ not considered for image statistics
llx lower left X corner pix
lly upper left Y corner pix
urx lower right X corner pix
ury upper right Y corner pix
Returns:
Bad pixel mask image (1: good pixel, 0: bad pixel).

Job this routine searches for static bad pixel positions This is done by building a cube of xsh_dark frames and examine the noise variations in each pixel. If big deviations from a clean mean pixel noise occurr, the pixel is declared as bad.

Definition at line 1429 of file xsh_utils_image.c.

References _STATS_::cleanmean, _STATS_::cleanstdev, n, QFLAG_HOT_PIXEL, xsh_image_stats_on_rectangle(), xsh_msg_error, and xsh_pixel_qsort().

Referenced by xsh_get_master_dark_nir_via_noise().

cpl_image* xsh_image_smooth_fft ( cpl_image *  inp,
const int  fx,
const int  fy 
)

Definition at line 1896 of file xsh_utils_image.c.

References check, cknull_msg, filter, xsh_free_image(), and xsh_gen_lowpass().

cpl_image* xsh_image_smooth_mean_x ( cpl_image *  inp,
const int  r 
)

Definition at line 2183 of file xsh_utils_image.c.

References check, and XSH_ASSURE_NOT_NULL.

cpl_image* xsh_image_smooth_mean_y ( cpl_image *  inp,
const int  r 
)

Definition at line 2073 of file xsh_utils_image.c.

References check, XSH_ASSURE_NOT_NULL, and xsh_free_image().

cpl_image* xsh_image_smooth_median_x ( cpl_image *  inp,
const int  r 
)

Definition at line 2241 of file xsh_utils_image.c.

References check, and cknull_msg.

Referenced by xsh_mflat_normalize().

cpl_image* xsh_image_smooth_median_xy ( cpl_image *  inp,
const int  r 
)

Definition at line 2304 of file xsh_utils_image.c.

References check, and cknull_msg.

cpl_image* xsh_image_smooth_median_y ( cpl_image *  inp,
const int  r 
)

Definition at line 2128 of file xsh_utils_image.c.

References check, and cknull_msg.

cpl_error_code xsh_image_warp_polynomial_scale ( cpl_image *  out,
const cpl_polynomial *  poly_x,
const cpl_polynomial *  poly_y 
)

Compute area change ratio for a 2D polynomial transformation.

Parameters:
out Pre-allocated image to hold the result
poly_x Defines source x-pos corresponding to destination (u,v).
poly_y Defines source y-pos corresponding to destination (u,v).
Returns:
CPL_ERROR_NONE or the relevant _cpl_error_code_ on error
See also:
cpl_image_warp_polynomial()

Given a polynomial transformation from (x, y) to (u, v) coordinate systems, such as the one used in cpl_image_warp_polynomial() to "warp" (or "map") an image onto another, this function creates an image reporting for each pixel the scaling ratio between the unitary area in the system (u, v) and the same area before mapping, in the system (x, y).

This is trivially obtained by computing the absolute value of the determinant of the Jacobian of the transformation for each pixel of the image out.

Typically this function would be used to determine a flux-conservation correction map for the target image specified in function cpl_image_warp_polynomial(). For example,

 * cpl_image_warp_polynomial(out, in, poly_x, poly_y, xprof, xrad, yprof, yrad);
 * correction_map = cpl_image_new(cpl_image_get_size_x(out),
 *                                cpl_image_get_size_y(out),
 *                                cpl_image_get_type(out));
 * cpl_image_warp_polynomial_scale(correction_map, poly_x, poly_y);
 * out_flux_corrected = cpl_image_multiply_create(out, correction_map);
 * 

where out_flux_corrected is the resampled image out after correction for flux conservation.

Note:
The scale map produced by this function is not applicable for flux conservation in case the transformation implies severe undersampling of the original signal.

Possible _cpl_error_code_ set in this function:

  • CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL
  • CPL_ERROR_ILLEGAL_INPUT if the polynomial dimensions are not 2
  • CPL_ERROR_INVALID_TYPE if the passed image type is not supported

Definition at line 1012 of file xsh_utils_image.c.

References nx, and ny.

cpl_error_code xsh_iml_merge_avg ( cpl_imagelist **  data,
cpl_imagelist **  mask,
const cpl_image *  data_ima,
const cpl_image *  mask_ima,
const int  mk 
)

merge imagelist via average

Parameters:
[in] data imagelist
[in] mask corresponding mask
[out] data_ima average image
[out] mask_ima corresponding mask
[in] mk index

Definition at line 3285 of file xsh_utils_image.c.

References check, and size.

Referenced by xsh_build_ifu_cube(), and xsh_util_ifu_build_cube().

void xsh_pixel_qsort ( pixelvalue pix_arr,
int  npix 
)

Definition at line 1739 of file xsh_utils_image.c.

References PIX_STACK_SIZE, PIX_SWAP, and xsh_msg_error.

Referenced by xsh_clean_mean(), and xsh_image_search_bad_pixels_via_noise().

cpl_image* xsh_scharr_x ( cpl_image *  in  ) 

Compute X Scharr filter transformation.

Parameters:
in input image
Returns:
X scarr filter image http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1131 of file xsh_utils_image.c.

References check.

Referenced by main(), and xsh_compute_flat_edges().

cpl_image* xsh_scharr_y ( cpl_image *  in  ) 

Compute Y Scharr filter transformation.

Parameters:
in input image
Returns:
Y scharr filter image http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1170 of file xsh_utils_image.c.

References check.

Referenced by main().

void xsh_show_interpolation_kernel ( char *  kernel_name  ) 

Definition at line 649 of file xsh_utils_image.c.

References KERNEL_SAMPLES, TABSPERPIX, x, and xsh_generate_interpolation_kernel().

cpl_image* xsh_sobel_lx ( cpl_image *  in  ) 

Compute X Sobel filter transformation.

Parameters:
in input image
Returns:
X scharr filter image http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1208 of file xsh_utils_image.c.

References check.

Referenced by main(), and xsh_compute_flat_edges().

cpl_image* xsh_sobel_ly ( cpl_image *  in  ) 

Compute Y Sobel filter transformation.

Parameters:
in input image
Returns:
Y scharr filter image http://en.wikipedia.org/wiki/Sobel_operator

Definition at line 1248 of file xsh_utils_image.c.

References check.

Referenced by main().

cpl_image* xsh_warp_image_generic ( cpl_image *  image_in,
char *  kernel_type,
cpl_polynomial *  poly_u,
cpl_polynomial *  poly_v 
)

Definition at line 344 of file xsh_utils_image.c.

References TABSPERPIX, x, xsh_generate_interpolation_kernel(), xsh_msg_error, and y.

Referenced by main().


Generated on 13 Mar 2013 for X-shooter Pipeline Reference Manual by  doxygen 1.6.1