GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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 }
int I_cluster_signatures(struct Cluster *C)
Create signatures.
Definition: c_sig.c:23
int I_new_signature(struct Signature *)
Definition: sig.c:30
if(!(yy_init))
Definition: sqlp.yy.c:775
Definition: cluster.h:7
int * count
Definition: cluster.h:18
int npoints
Definition: cluster.h:9
struct Signature S
Definition: cluster.h:24
int * class
Definition: cluster.h:16
int nclasses
Definition: cluster.h:26
DCELL ** points
Definition: cluster.h:10
double ** sum
Definition: cluster.h:20
int nbands
Definition: cluster.h:8
int status
Definition: imagery.h:52
int npoints
Definition: imagery.h:49
double * mean
Definition: imagery.h:50
double ** var
Definition: imagery.h:51
struct One_Sig * sig
Definition: imagery.h:64