GRASS 8 Programmer's Manual
8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
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
*/
23
int
I_cluster_signatures
(
struct
Cluster
*C)
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
}
I_cluster_signatures
int I_cluster_signatures(struct Cluster *C)
Create signatures.
Definition
c_sig.c:23
AMI_STREAM
Definition
ami_stream.h:153
cluster.h
I_new_signature
int I_new_signature(struct Signature *)
Definition
sig.c:30
Cluster
Definition
cluster.h:7
Cluster::count
int * count
Definition
cluster.h:18
Cluster::npoints
int npoints
Definition
cluster.h:9
Cluster::S
struct Signature S
Definition
cluster.h:24
Cluster::class
int * class
Definition
cluster.h:16
Cluster::nclasses
int nclasses
Definition
cluster.h:26
Cluster::points
DCELL ** points
Definition
cluster.h:10
Cluster::sum
double ** sum
Definition
cluster.h:20
Cluster::nbands
int nbands
Definition
cluster.h:8
lib
cluster
c_sig.c
Generated on Fri Apr 3 2026 06:59:52 for GRASS 8 Programmer's Manual by
1.9.8