irplib_filter.c

00001 /* $Id: irplib_filter.c,v 1.24 2009/10/14 15:48:04 llundin Exp $
00002  *
00003  * This file is part of the irplib package 
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., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2009/10/14 15:48:04 $
00024  * $Revision: 1.24 $
00025  * $Name: HEAD $
00026  */
00027 
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 
00033 
00034 /*-----------------------------------------------------------------------------
00035                                  Includes
00036  -----------------------------------------------------------------------------*/
00037 
00038 #include "irplib_filter.h"
00039 
00040 /*----------------------------------------------------------------------------*/
00056 /*----------------------------------------------------------------------------*/
00057 
00058 
00059 /*-----------------------------------------------------------------------------
00060                             Function definitions
00061  -----------------------------------------------------------------------------*/
00062 
00065 /*----------------------------------------------------------------------------*/
00079 /*----------------------------------------------------------------------------*/
00080 cpl_error_code irplib_image_filter_background_line(cpl_image * self,
00081                                                    const cpl_image * other,
00082                                                    int hsize,
00083                                                    cpl_boolean vertical)
00084 {
00085     const int      nx = cpl_image_get_size_x(self);
00086     const int      ny = cpl_image_get_size_y(self);
00087     const int      msize = 1 + 2 * hsize;
00088     cpl_mask     * mask;
00089     cpl_image    * background;
00090     cpl_error_code error = CPL_ERROR_NONE;
00091 
00092     cpl_ensure_code(self  != NULL, CPL_ERROR_NULL_INPUT);
00093     cpl_ensure_code(hsize >= 0,    CPL_ERROR_ILLEGAL_INPUT);
00094 
00095     if (other == NULL) other = self;
00096 
00097     mask = vertical ? cpl_mask_new(msize, 1) : cpl_mask_new(1, msize);
00098 
00099     error |= cpl_mask_not(mask);
00100 
00101     background = cpl_image_new(nx, ny, cpl_image_get_type(other));
00102 
00103     error |= cpl_image_filter_mask(background, other, mask, CPL_FILTER_MEDIAN,
00104                                    CPL_BORDER_FILTER);
00105     cpl_mask_delete(mask);
00106 
00107     if (self != other) {
00108         error |= cpl_image_copy(self, other, 1, 1);
00109     }
00110 
00111     error |= cpl_image_subtract(self, background);
00112     cpl_image_delete(background);
00113 
00114     return error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
00115 }

Generated on Wed Mar 9 15:46:16 2011 for NACO Pipeline Reference Manual by  doxygen 1.5.8