VIRCAM Pipeline 2.3.12
moments.c
1/* $Id: moments.c,v 1.3 2015/08/12 11:16:55 jim Exp $
2 *
3 * This file is part of the CASU Pipeline utilities
4 * Copyright (C) 2015 European Southern Observatory
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: 2015/08/12 11:16:55 $
24 * $Revision: 1.3 $
25 * $Name: $
26 */
27
28#include <stdio.h>
29#include <stdlib.h>
30
31#include "imcore.h"
32#include "util.h"
33
36/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65extern void imcore_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: moments.c,v $
144Revision 1.3 2015/08/12 11:16:55 jim
145Modified procedure names to protect namespace
146
147Revision 1.2 2015/08/07 13:06:54 jim
148Fixed copyright to ESO
149
150Revision 1.1.1.1 2015/06/12 10:44:32 jim
151Initial import
152
153Revision 1.2 2014/04/09 09:09:51 jim
154Detabbed
155
156Revision 1.1.1.1 2013/08/27 12:07:48 jim
157Imported
158
159
160
161*/
void imcore_moments(ap_t *ap, float results[])
Do moments analysis on an object.
Definition: moments.c:65