VIRCAM Pipeline  1.3.4
moments.c
1 /* $Id: moments.c,v 1.3 2010-09-09 12:09:57 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2010-09-09 12:09:57 $
24  * $Revision: 1.3 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include "imcore.h"
32 #include "util.h"
33 
36 /*---------------------------------------------------------------------------*/
63 /*---------------------------------------------------------------------------*/
64 
65 extern void moments(ap_t *ap, float results[]) {
66  int i,np;
67  float x,y,xoff,yoff,xsum,ysum,xsumsq,ysumsq,tsum,xysum,t,tmax,twelfth;
68  float xbar,ybar,sxx,syy,sxy,xintmin,w,wsum,xsum_w,ysum_w;
69  plstruct *plarray;
70 
71  /* Initialise a few things */
72 
73  xintmin = ap->xintmin;
74  plarray = ap->plarray;
75  np = ap->npl_pix;
76  xoff = (float)plarray[0].x;
77  yoff = (float)plarray[0].y;
78  xsum = 0.0;
79  ysum = 0.0;
80  xsum_w = 0.0;
81  ysum_w = 0.0;
82  wsum = 0.0;
83  xsumsq = 0.0;
84  ysumsq = 0.0;
85  tsum = 0.0;
86  xysum = 0.0;
87  tmax = plarray[0].z;
88  twelfth = 1.0/12.0;
89 
90  /* Do a moments analysis on an object */
91 
92  for (i = 0; i < np; i++) {
93  x = (float)plarray[i].x - xoff;
94  y = (float)plarray[i].y - yoff;
95  t = plarray[i].z;
96  w = plarray[i].zsm;
97  if (t < 0.0)
98  continue;
99  xsum += t*x;
100  ysum += t*y;
101  tsum += t;
102  xsum_w += w*t*x;
103  ysum_w += w*t*y;
104  wsum += w*t;
105  tmax = MAX(tmax,plarray[i].z);
106  xsumsq += (x*x + twelfth)*t;
107  ysumsq += (y*y + twelfth)*t;
108  xysum += x*y*t;
109  }
110 
111  /* Check that the total intensity is enough and if it is, then do
112  the final results */
113 
114  if (tsum >= xintmin) {
115  xbar = xsum/tsum;
116  ybar = ysum/tsum;
117  sxx = MAX(0.0,(xsumsq/tsum-xbar*xbar));
118  syy = MAX(0.0,(ysumsq/tsum-ybar*ybar));
119  sxy = xysum/tsum - xbar*ybar;
120  xbar = xsum_w/wsum;
121  ybar = ysum_w/wsum;
122  xbar += xoff;
123  ybar += yoff;
124  xbar = MAX(1.0,MIN(xbar,ap->lsiz));
125  ybar = MAX(1.0,MIN(ybar,ap->csiz));
126  results[0] = 1.0;
127  results[1] = xbar;
128  results[2] = ybar;
129  results[3] = tsum;
130  results[4] = sxx;
131  results[5] = sxy;
132  results[6] = syy;
133  results[7] = tmax;
134  } else {
135  results[0] = -1.0;
136  }
137 }
138 
141 /*
142 
143 $Log: not supported by cvs2svn $
144 Revision 1.2 2006/08/21 09:07:29 jim
145 Modified centring algorithm
146 
147 Revision 1.1 2005/09/13 13:25:30 jim
148 Initial entry after modifications to make cpl compliant
149 
150 
151 */
void moments(ap_t *ap, float results[])
Do moments analysis on an object.
Definition: moments.c:65