Debian Codegraph @

gui/XAlice/libsrc/filter.c

raw
1 /* @(#)filter.c 19.1 (ES0-DMD) 02/25/03 13:43:11 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /* @(#)filter.c 19.1 (ESO) 02/25/03 13:43:11 */
30
31 #include <math.h>
32 mean_filter(ina,len,width,outa)
33 float *ina, *outa;
34 int len,width;
35 {
36 double sum;
37 int midpt,i,j,k,endpt;
38 midpt = width/2;
39 endpt = len - midpt;
40 sum =0.0;
41 for(i=0;i < width ; i ++)
42 sum += ina[i];
43 for(i=0,k=width,j=midpt; j <endpt; j++,i++,k++)
44 {
45 outa[j] = sum / width;
46 sum += ina[k] - ina[i];
47 }
48 for(i=0;i<midpt ; i++)
49 {
50 outa[i] = outa[midpt];
51 outa[len - i - 1] = outa[len- midpt - 1];
52 }
53 }
54
55 median_filter(ina,len,width,outa)
56 float *ina, *outa;
57 int len,width;
58 {
59 float xxx[1000];
60 float xmed;
61 int midpt,i,j,k,endpt,ii;
62 midpt = width/2;
63 endpt = len - midpt;
64 for(i=0,k=width,j=midpt; j <endpt; j++,i++,k++)
65 {
66 for(ii=0;ii<width;ii++)
67 xxx[ii+1] = ina[i+ii];
68 /*mdian3(ina,i,k-1,&xmed);*/
69 mdian1(xxx,width,&xmed);
70 outa[j] = xmed;
71 }
72 for(i=0;i<midpt ; i++)
73 {
74 outa[i] = outa[midpt];
75 outa[len - i - 1] = outa[len- midpt - 1];
76 }
77 }