image_ops.h

00001 #ifndef IMAGE_OPS_H
00002 #define IMAGE_OPS_H
00003 /*******************************************************************************
00004 * E.S.O. - VLT project
00005 *
00006 * "@(#) $Id: image_ops.h,v 1.7 2005/07/04 15:42:57 amodigli Exp $"
00007 *
00008 * who       when      what
00009 * --------  --------  ----------------------------------------------
00010 * schreib  22/05/00  created
00011 */
00012 
00013 /************************************************************************
00014  * image_ops.h
00015  * image arithmetic routines
00016  *----------------------------------------------------------------------
00017  */
00018 
00019 /*
00020  * header files
00021  */
00022 
00023 /*
00024 #include <stdio.h>
00025 #include <math.h>
00026 #include "eclipse.h"
00027 #include "recipes.h"
00028 */
00029 #include <qfits.h>
00030 #include <cpl.h>
00031 
00032 #include "spectrum_ops.h" 
00033 
00034 /*----------------------------------------------------------------------------
00035  *                      Function ANSI C prototypes
00036  *--------------------------------------------------------------------------*/
00037 
00038 /*----------------------------------------------------------------------------
00039    Function     :       meanOfColumns()
00040    In           :       image
00041    Out          :       resulting row array
00042    Job          :       takes the average of each image column
00043  ---------------------------------------------------------------------------*/
00044 /*<python>*/
00045 Vector * meanOfColumns( OneImage * im ) ;
00046 /*</python>*/
00047 
00048 /*----------------------------------------------------------------------------
00049    Function     :       cleanMeanOfColumns()
00050    In           :       image , percentage of lowest and highest values to
00051                         reject
00052    Out          :       resulting row image
00053    Job          :       takes the average of each image column by sorting the
00054                         column values and rejecting the given percentage of
00055                         the highest and lowest values  [0...1]
00056  ---------------------------------------------------------------------------*/
00057 
00058 double median_image(OneImage* im);
00059 
00060 /*<python>*/
00061 OneImage * cleanMeanOfColumns( OneImage * im,
00062                                float lo_reject,
00063                                float hi_reject) ;
00064 /*</python>*/
00065 
00066 
00067 /*----------------------------------------------------------------------------
00068    Function     :       divImageByRow()
00069    In           :       image, row array
00070    Out          :       resulting image
00071    Job          :       divides each image column by a row value
00072  ---------------------------------------------------------------------------*/
00073 
00074 /*<python>*/
00075 OneImage * divImageByRow( OneImage * im, Vector * row ) ;
00076 /*</python>*/
00077 
00078 /*----------------------------------------------------------------------------
00079    Function     :       multRowToImage()
00080    In           :       image, row array
00081    Out          :       resulting image
00082    Job          :       multiplies each image column with a row value
00083  ---------------------------------------------------------------------------*/
00084 
00085 /*<python>*/
00086 OneImage * multRowToImage( OneImage *im, Vector *row ) ;
00087 /*</python>*/
00088 
00089 /*----------------------------------------------------------------------------
00090    Function     :       colTilt()
00091    In           :       image , factor of sigma noise limit to determine 
00092                         pixels that are used for the fit.
00093    Out          :       image
00094    Job          :       first calculates statistics for each column of an image.
00095                         median value and standard deviation of columns are de-
00096                         termined, blank values are excluded. Fits a straight 
00097                         line through the pixel values of each column and subtracts
00098                         the fit in order to remove the tilt of each column.
00099                         Only those pixels are used for the fit that are within 
00100                         a defined factor of sigma noise limit. The noise is 
00101                         calculated from pixels between the 10percentil and 
00102                         90percentil points. 
00103    Notice       :       works only for raw or averaged raw images
00104  ---------------------------------------------------------------------------*/
00105 
00106 /*<python>*/
00107 OneImage * colTilt ( OneImage * image, float sigmaFactor ) ;
00108 /*</python>*/
00109 
00110 /*----------------------------------------------------------------------------
00111    Function     :       medianImage()
00112    In           :       image, a median threshold parameter
00113    Out          :       resulting image
00114    Job          :       median filter, calculates the median for an image
00115                         by using the 8 closest pixels to each pixel.
00116                         The values in the output image are determined according
00117                         to the values of the input parameter. 
00118                         If fmedian = 0: always replace by median
00119                         if fmedian < 0: replace by median if |pixel - median| >
00120                                         -fmedian
00121                         if fmedian > 0: replace by median if (fmedian as a factor of
00122                                         the square root of the median itself)
00123                                         if |pixel - median| >= fmedian * sqrt ( median )
00124                                         This can be used to consider photon noise.
00125                                         This considers a dependence of the differences on the
00126                                         pixel values themselves.
00127    Notice       :       it is assumed that most of the 8 nearest neighbor pixels
00128                         are not bad pixels!
00129                         blank pixels are not replaced!
00130  ---------------------------------------------------------------------------*/
00131 
00132 /*<python>*/
00133 OneImage * medianImage( OneImage * im, float fmedian ) ;
00134 /*</python>*/
00135 
00136 /*----------------------------------------------------------------------------
00137    Function     :       compareImages()
00138    In           :       two images to be compared and the original image
00139    Out          :       resulting image
00140    Job          :       if a pixel value of one image (im1) equals
00141                         the pixel value of the other image keep the 
00142                         pixel value of the original image otherwise replace 
00143                         it with ZEROs
00144  ---------------------------------------------------------------------------*/
00145 
00146 /*<python>*/
00147 OneImage * compareImages( OneImage * im1, OneImage * im2, OneImage * origim ) ;
00148 /*</python>*/
00149 
00150 /*----------------------------------------------------------------------------
00151    Function     :       threshImage()
00152    In           :       image, low cut pixel value, high cut pixel value
00153    Out          :       resulting image
00154    Job          :       simple search for static bad pixels for a flat field
00155                         or dark frame, values below and above the threshold
00156                         values are set to BLANK.
00157  ---------------------------------------------------------------------------*/
00158 
00159 /*<python>*/
00160 OneImage * threshImage ( OneImage * im, float lo_cut, float hi_cut ) ;
00161 /*</python>*/
00162 
00163 /*----------------------------------------------------------------------------
00164    Function     :       promoteImageToPixelmap()
00165    In           :       image
00166    Out          :       resulting pixelmap
00167    Job          :       changes an image with BLANK indicated bad pixels to
00168                         a bad pixel map.
00169  ---------------------------------------------------------------------------*/
00170 
00171 pixel_map * promoteImageToPixelmap ( OneImage * im ) ;
00172 
00173 /*----------------------------------------------------------------------------
00174    Function     :       promoteImageToMask()
00175    In           :       image with ZERO indicating bad pixels
00176    Out          :       resulting mask image that means 1 for good pixels
00177                         and ZEROS for bad pixel positions
00178                         n_badpixels: number of bad pixels
00179    Job          :       changes an image with ZERO indicated bad pixels to
00180                         a bad pixel mask image, that means the returned
00181                         image has values 1 at positions of good pixels and
00182                         ZEROs at positions of bad pixels.
00183  ---------------------------------------------------------------------------*/
00184 
00185 /*<python>*/
00186 OneImage * promoteImageToMask ( OneImage * im, int * n_badpixels ) ;
00187 /*</python>*/
00188 
00189 /*----------------------------------------------------------------------------
00190    Function     :       multImageByMask()
00191    In           :       im:   input image
00192                         mask: mask image
00193    Out          :       resulting image that means the input image with marked
00194                         static bad pixels (ZERO values)
00195    Job          :       changes an image to an image that has ZERO indicated 
00196                         static bad pixels
00197  ---------------------------------------------------------------------------*/
00198 
00199 /*<python>*/
00200 OneImage * multImageByMask ( OneImage * im, OneImage * mask ) ;
00201 /*</python>*/
00202 
00203 
00204 /*----------------------------------------------------------------------------
00205    Function     :       interpolImage()
00206    In           :       im: raw image
00207                         mask: bad pixel mask
00208                         max_radius: maximum x and y distance in pixels from the
00209                                     bad pixel within which valid pixels for
00210                                     interpolation are searched.
00211                         n_pixels:   minimal number of pixels with which the bad
00212                                     pixel is interpolated if not enough
00213                                     valid nearest neighbors are found.
00214    Out          :       resulting interpolated image without any ZEROS
00215    Job          :       interpolates all bad pixels indicated by the bad pixel mask.
00216                         Therefore, the mean of at least 2 valid values of
00217                         the nearest 8 neighbors is taken. If too much
00218                         neighbors are also bad pixels
00219                         the neighbor radius is increased to a maximum of
00220                         max_radius until n_pixels valid pixels are found.
00221                         The valid neighbors are searched by going through
00222                         the columns and rows around the central square that
00223                         was already searched.
00224                         The bad pixel is interpolated by the mean of these
00225                         valid pixels (less than 9) or by the median of them
00226                         (more than 8).
00227  ---------------------------------------------------------------------------*/
00228 /*<python>*/
00229 OneImage * interpolImage ( OneImage * im,
00230                            OneImage * mask,
00231                            int        max_radius,
00232                            int        n_pixels ) ;
00233 /*</python>*/
00234 
00235 /*----------------------------------------------------------------------------
00236    Function     :       interpolSourceImage()
00237    In           :       im:         source raw image
00238                         mask:       bad pixel mask
00239                         max_rad:    maximum pixel distance from the bad pixel to
00240                                     interpolate where valid pixel values are searched for.
00241                         slit_edges: array of the edges of the slitlets.
00242    Out          :       resulting interpolated image hopefully without any ZEROS
00243    Job          :       interpolates all bad pixels indicated by the bad pixel mask.
00244                         Therefore, the mean of the nearest 4 neighbors is taken,
00245                         two in spectral direction and 2 in spatial direction.
00246                         The routine cares about the image and slitlet edges.
00247                         If there are no good pixel found within the nearest neighbors,
00248                         the next 4 nearest neighbors in spatial and spectral direction
00249                         are searched for valid pixels until a limit of max_rad.
00250                         A maximum of 4 valid pixels are used for interpolation by their mean.
00251  ---------------------------------------------------------------------------*/
00252 /*<python>*/
00253 OneImage * interpolSourceImage ( OneImage * im,
00254                                  OneImage * mask,
00255                                  int        max_rad,
00256                                  float   ** slit_edges ) ;
00257 /*</python>*/
00258 
00259 /*----------------------------------------------------------------------------
00260    Function     :       stackRowToImage()
00261    In           :       row: one image row as vector data structure
00262                         ly:  image length
00263    Out          :       resulting image
00264    Job          :       stack a given image row to build a whole image
00265  ---------------------------------------------------------------------------*/
00266 
00267 /*<python>*/
00268 OneImage * stackRowToImage ( Vector * row, int ly ) ;
00269 /*</python>*/
00270 
00271 /*----------------------------------------------------------------------------
00272    Function     :       imageStatsOnRectangle()
00273    In           :       im: flatfield image to search for bad pix
00274                         loReject, hiReject: percentage (0...100) of extrem values
00275                                             that should not be considered
00276                         llx, lly: lower left pixel position of rectangle
00277                         urx, ury: upper right pixel position of rectangle
00278    Out          :       data structure giving the mean and standard deviation
00279    Job          :       computes the mean and standard deviation of
00280                         a given rectangle on an image by leaving the extreme
00281                         intensity values.
00282  ---------------------------------------------------------------------------*/
00283 
00284 /*<python>*/
00285 Stats * imageStatsOnRectangle ( OneImage * im,
00286                                 float      loReject,
00287                                 float      hiReject,
00288                                 int        llx,
00289                                 int        lly,
00290                                 int        urx,
00291                                 int        ury ) ;
00292 /*</python>*/
00293 
00294 /*----------------------------------------------------------------------------
00295    Function     :       normalize_to_central_pixel()
00296    In           :       image: image to normalize
00297    Out          :       resulting image
00298    Job          :       normalizes a raw flatfield image by dividing by the median of the central
00299                         spectral pixels to produce a master flatfield
00300  ---------------------------------------------------------------------------*/
00301 
00302 /*<python>*/
00303 OneImage * normalize_to_central_pixel ( OneImage * image ) ;
00304 /*</python>*/
00305 
00306 /*-------------------------------------------------------------------------*/
00335 /*--------------------------------------------------------------------------*/
00336 
00337 /*<python>*/
00338 OneImage *
00339 shiftImage(
00340     OneImage    *    image_in,
00341     double           shift_x,
00342     double           shift_y,
00343     double       *   interp_kernel) ;
00344 /*</python>*/
00345 
00346 void
00347 shiftImageinCube(
00348     OneImage     *   image_in,
00349     double           shift_x,
00350     double           shift_y,
00351     double       *   interp_kernel,
00352     OneImage     *   shifted,
00353     pixelvalue   *   first_pass) ;
00354 
00355 /*<python>*/
00356 void delStats (Stats *) ;
00357 /*</python>*/
00358 
00359 /*----------------------------------------------------------------------------
00360    Function     :       combineMasks()
00361    In           :       firstMask, secondMask: bad pixel masks to combine
00362    Out          :       resulting image
00363    Job          :       combines two bad pixel mask to one using an or relation
00364  ---------------------------------------------------------------------------*/
00365 
00366 /*<python>*/
00367 OneImage * combineMasks ( OneImage * firstMask, OneImage * secondMask ) ;
00368 /*</python>*/
00369 
00370 /*----------------------------------------------------------------------------
00371    Function     :       sliceCube()
00372    In           :       cube: input reduced data cube
00373                         x, y: x slice or y slice pixel value
00374    Out          :       resulting slice image
00375    Job          :       slices a data cube in x or y direction
00376  ---------------------------------------------------------------------------*/
00377 
00378 /*<python>*/
00379 OneImage * sliceCube ( OneCube * cube, int x, int y ) ;
00380 /*</python>*/
00381 
00382 /*----------------------------------------------------------------------------
00383    Function     :       divImagesRobust()
00384    In           :       im1, im2: input images im1/im2
00385    Out          :       resulting divided image
00386    Job          :       divides two images by considering blanks and
00387                         calculating first 1/im2 by
00388                         cutting the very high values and setting to 1,
00389                         then multiplying im1 * 1/im2.
00390  ---------------------------------------------------------------------------*/
00391 
00392 /*<python>*/
00393 OneImage * divImagesRobust ( OneImage * im1, OneImage * im2 ) ;
00394 /*</python>*/
00395 
00396 /*<python>*/
00397 OneImage * nullEdges ( OneImage * image) ;
00398 /*</python>*/
00399 
00400 /*<python>*/
00401 void usedcormap( OneImage *im, OneImage *map);
00402 /*</python>*/
00403 
00404 #endif 
00406 /*--------------------------------------------------------------------------*/

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