/* $Id: cpl_stats-test.c,v 1.21 2008/02/07 10:54:01 llundin Exp $ * * This file is part of the ESO Common Pipeline Library * Copyright (C) 2001-2004 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: llundin $ * $Date: 2008/02/07 10:54:01 $ * $Revision: 1.21 $ * $Name: $ */ /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #include #include #include #include "cpl_stats.h" #include "cpl_image_gen.h" #include "cpl_image_io.h" #include "cpl_image_bpm.h" #include "cpl_memory.h" #include "cpl_tools.h" /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ int main(void) { cpl_image * imf; cpl_image * imd; cpl_image * imi; cpl_stats * stats; double med1, med2; double sig; int is_rejected; FILE * stream = NULL; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); if (cpl_msg_get_level() > CPL_MSG_INFO) { stream = fopen("/dev/null", "a"); } if (stream == NULL) stream = stdout; /* Insert tests below */ /* FIXME: : Extend test to more than absence of failure... */ /* Create images: imf1, imf2, imd1, imd2, imi1, imi2 */ cpl_test( imd = cpl_image_fill_test_create(512, 512) ); cpl_test( imf = cpl_image_cast(imd, CPL_TYPE_FLOAT) ); cpl_test( imi = cpl_image_cast(imd, CPL_TYPE_INT) ); /* Get statistics on the imi */ cpl_msg_info("","Get statistics on imi:"); cpl_test( stats = cpl_stats_new_from_image(imi, CPL_STATS_ALL) ); cpl_test_zero( cpl_stats_dump(stats, CPL_STATS_ALL, stream) ); cpl_stats_delete(stats); /* Get statistics on the imf */ cpl_msg_info("","Get statistics on imf:"); cpl_test( stats = cpl_stats_new_from_image(imf, CPL_STATS_ALL) ); cpl_test_zero( cpl_stats_dump(stats, CPL_STATS_ALL, stream) ); cpl_stats_delete(stats); /* Get statistics on the imd */ cpl_msg_info("","Get statistics on imd:"); cpl_test( stats = cpl_stats_new_from_image(imd, CPL_STATS_ALL) ); cpl_test_zero( cpl_stats_dump(stats, CPL_STATS_ALL, stream) ); cpl_stats_delete(stats); cpl_image_delete(imi); cpl_image_delete(imd); med2 = cpl_image_get_median(imf); /* Test cpl_image_get_median_dev() */ med1 = cpl_image_get_median_dev(imf, &sig); cpl_test( fabs(med1-med2) <= 2*DBL_EPSILON * fabs(med1) ); /* Test cpl_image_get() on a bad pixel */ cpl_test_zero( cpl_image_reject(imf, 10, 10) ); med1 = cpl_image_get(imf, 10, 10, &is_rejected); cpl_test_error( CPL_ERROR_NONE); cpl_test( is_rejected ); /* Free and return */ cpl_image_delete(imf); if (stream != stdout) cpl_test_zero( fclose(stream) ); /* End of tests */ return cpl_test_end(0); }