00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030
00031 #include "imcore.h"
00032 #include "util.h"
00033
00036
00063
00064
00065 extern void moments(ap_t *ap, float results[]) {
00066 int i,np;
00067 float x,y,xoff,yoff,xsum,ysum,xsumsq,ysumsq,tsum,xysum,t,tmax,twelfth;
00068 float xbar,ybar,sxx,syy,sxy,xintmin,w,wsum,xsum_w,ysum_w;
00069 plstruct *plarray;
00070
00071
00072
00073 xintmin = ap->xintmin;
00074 plarray = ap->plarray;
00075 np = ap->npl_pix;
00076 xoff = (float)plarray[0].x;
00077 yoff = (float)plarray[0].y;
00078 xsum = 0.0;
00079 ysum = 0.0;
00080 xsum_w = 0.0;
00081 ysum_w = 0.0;
00082 wsum = 0.0;
00083 xsumsq = 0.0;
00084 ysumsq = 0.0;
00085 tsum = 0.0;
00086 xysum = 0.0;
00087 tmax = plarray[0].z;
00088 twelfth = 1.0/12.0;
00089
00090
00091
00092 for (i = 0; i < np; i++) {
00093 x = (float)plarray[i].x - xoff;
00094 y = (float)plarray[i].y - yoff;
00095 t = plarray[i].z;
00096 w = plarray[i].zsm;
00097 if (t < 0.0)
00098 continue;
00099 xsum += t*x;
00100 ysum += t*y;
00101 tsum += t;
00102 xsum_w += w*t*x;
00103 ysum_w += w*t*y;
00104 wsum += w*t;
00105 tmax = MAX(tmax,plarray[i].z);
00106 xsumsq += (x*x + twelfth)*t;
00107 ysumsq += (y*y + twelfth)*t;
00108 xysum += x*y*t;
00109 }
00110
00111
00112
00113
00114 if (tsum >= xintmin) {
00115 xbar = xsum/tsum;
00116 ybar = ysum/tsum;
00117 sxx = MAX(0.0,(xsumsq/tsum-xbar*xbar));
00118 syy = MAX(0.0,(ysumsq/tsum-ybar*ybar));
00119 sxy = xysum/tsum - xbar*ybar;
00120 xbar = xsum_w/wsum;
00121 ybar = ysum_w/wsum;
00122 xbar += xoff;
00123 ybar += yoff;
00124 xbar = MAX(1.0,MIN(xbar,ap->lsiz));
00125 ybar = MAX(1.0,MIN(ybar,ap->csiz));
00126 results[0] = 1.0;
00127 results[1] = xbar;
00128 results[2] = ybar;
00129 results[3] = tsum;
00130 results[4] = sxx;
00131 results[5] = sxy;
00132 results[6] = syy;
00133 results[7] = tmax;
00134 } else {
00135 results[0] = -1.0;
00136 }
00137 }
00138
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154