GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
c_sig.c
Go to the documentation of this file.
1 /*!
2  \file cluster/c_sig.c
3 
4  \brief Cluster library - Signatures
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <grass/cluster.h>
15 
16 /*!
17  \brief Create signatures
18 
19  \param C pointer to Cluster structure
20 
21  \return 0
22 */
24 {
25  int c, p, band1, band2;
26  int n;
27  double m1, m2;
28  double p1, p2;
29  double dn;
30 
31  /*
32  fprintf (stderr, "c_sig: 1\n");
33  fprintf (stderr, " nclasses %d\n", C->nclasses);
34  fprintf (stderr, " npoints %d\n", C->npoints );
35  fprintf (stderr, " nbands %d\n", C->nbands );
36  */
37  for (n = 0; n < C->nclasses; n++) {
38  I_new_signature(&C->S);
39  }
40 
41  for (p = 0; p < C->npoints; p++) {
42  c = C->class[p];
43  if (c < 0)
44  continue;
45  /*
46  if (c >= C->nclasses)
47  fprintf (stderr, " class[%d]=%d ** illegal **\n", p, c);
48  */
49  dn = n = C->count[c];
50  if (n < 2)
51  continue;
52  for (band1 = 0; band1 < C->nbands; band1++) {
53  m1 = C->sum[band1][c] / dn;
54  p1 = C->points[band1][p];
55  for (band2 = 0; band2 <= band1; band2++) {
56  m2 = C->sum[band2][c] / dn;
57  p2 = C->points[band2][p];
58  C->S.sig[c].var[band1][band2] += (p1 - m1) * (p2 - m2);
59  }
60  }
61  }
62 
63  for (c = 0; c < C->nclasses; c++) {
64  dn = n = C->S.sig[c].npoints = C->count[c];
65  if (n == 0)
66  dn = 1.0;
67  for (band1 = 0; band1 < C->nbands; band1++)
68  C->S.sig[c].mean[band1] = C->sum[band1][c] / dn;
69  dn = n = C->count[c] - 1;
70  if (n < 1)
71  continue;
72  for (band1 = 0; band1 < C->nbands; band1++)
73  for (band2 = 0; band2 <= band1; band2++)
74  C->S.sig[c].var[band1][band2] /= dn;
75  C->S.sig[c].status = 1;
76  }
77 
78  return 0;
79 }
if(!(yy_init))
Definition: sqlp.yy.c:775
int nbands
Definition: cluster.h:9
double ** sum
Definition: cluster.h:21
double ** var
Definition: imagery.h:57
int nclasses
Definition: cluster.h:27
int npoints
Definition: imagery.h:55
struct Signature S
Definition: cluster.h:25
Definition: cluster.h:7
int npoints
Definition: cluster.h:10
int * count
Definition: cluster.h:19
int * class
Definition: cluster.h:17
DCELL ** points
Definition: cluster.h:11
int status
Definition: imagery.h:58
struct One_Sig * sig
Definition: imagery.h:68
int I_new_signature(struct Signature *)
Definition: sig.c:16
double * mean
Definition: imagery.h:56
int I_cluster_signatures(struct Cluster *C)
Create signatures.
Definition: c_sig.c:23