hawki_variance.c

00001 /* $Id: hawki_variance.c,v 1.2 2009/03/13 11:52:06 cgarcia Exp $
00002  *
00003  * This file is part of the HAWKI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: cgarcia $
00023  * $Date: 2009/03/13 11:52:06 $
00024  * $Revision: 1.2 $
00025  * $Name: hawki-1_8_0 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <float.h>
00037 #include <string.h>
00038 #include <math.h>
00039 #include <cpl.h>
00040 
00041 #include "hawki_variance.h"
00042 
00043 /*----------------------------------------------------------------------------*/
00047 /*----------------------------------------------------------------------------*/
00048 
00051 /*----------------------------------------------------------------------------*/
00079 /*----------------------------------------------------------------------------*/
00080 cpl_image * hawki_image_create_variance
00081 (const cpl_image * image,
00082  double            gain,
00083  double            ron,
00084  int               ndit,
00085  int               ndsamples)
00086 {
00087     cpl_image    * variance;
00088     float        * variance_p;
00089     const float  * image_p;
00090     int            pix;
00091     int            npix;
00092     double         poisson_contrib;
00093     double         poisson_factor;
00094     double         ron_contrib;
00095     
00096 
00097     /* Test entries */
00098     if (image == NULL) return NULL;
00099 
00100     /* Create new image */
00101     variance = cpl_image_duplicate(image);
00102 
00103     /* Loop on pixels */
00104     variance_p = cpl_image_get_data(variance);
00105     image_p = cpl_image_get_data_const(image);
00106     npix = cpl_image_get_size_x(image) * cpl_image_get_size_y(image); 
00107     /* TODO: There is a Delta_t factor that appears in the Vacca article
00108      * that is not reflexed here! */ 
00109     ron_contrib = 12 * ron * ron / (gain * gain * ndsamples * ndit) *
00110         (ndsamples - 1) / (ndsamples + 1);
00111     poisson_factor = 6. / (5. * gain * ndsamples * ndit) * 
00112         (ndsamples * ndsamples + 1) / (ndsamples + 1);
00113     for(pix = 0; pix < npix; ++pix)
00114     {
00115         /* TODO: Include the effect of saturation in the TLI mode used by HAWK-I */
00116         poisson_contrib = poisson_factor * fabs(image_p[pix]);
00117         variance_p[pix] = poisson_contrib + ron_contrib;
00118     }
00119     
00120     /* Return */
00121     return variance;
00122 }
00123 
00124 /*----------------------------------------------------------------------------*/
00157 /*----------------------------------------------------------------------------*/
00158 cpl_imagelist * hawki_imglist_create_variances_and_delete
00159 (cpl_imagelist * imagelist_raw, 
00160  double          gain,
00161  double          ron,
00162  int             ndit,
00163  int             ndsamples)
00164 {
00165     cpl_imagelist  * variances;
00166     
00167     variances = cpl_imagelist_new();
00168     /* Loop on the frames */
00169     while(cpl_imagelist_get_size(imagelist_raw) > 0)
00170     {
00171         cpl_image * variance;
00172             
00173         variance = hawki_image_create_variance
00174             (cpl_imagelist_get(imagelist_raw, 0), gain, ron, ndit, ndsamples);
00175         cpl_imagelist_set(variances, variance, 
00176                           cpl_imagelist_get_size(variances));
00177         cpl_image_delete(cpl_imagelist_unset(imagelist_raw, 0));
00178     }
00179     return variances;
00180 }
00181 
00182 

Generated on Thu Feb 17 17:13:08 2011 for HAWKI Pipeline Reference Manual by  doxygen 1.4.7