GRASS 8 Programmer's Manual
8.6.0dev(2026)-8843f13794
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
SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7
SPDX-License-Identifier: GPL-2.0-or-later
8
9
\author Original author CERL
10
*/
11
12
#include <
grass/cluster.h
>
13
14
/*!
15
\brief Create signatures
16
17
\param C pointer to Cluster structure
18
19
\return 0
20
*/
21
int
I_cluster_signatures
(
struct
Cluster
*C)
22
{
23
int
c, p,
band1
,
band2
;
24
int
n;
25
double
m1, m2;
26
double
p1
, p2;
27
double
dn
;
28
29
/*
30
fprintf (stderr, "c_sig: 1\n");
31
fprintf (stderr, " nclasses %d\n", C->nclasses);
32
fprintf (stderr, " npoints %d\n", C->npoints );
33
fprintf (stderr, " nbands %d\n", C->nbands );
34
*/
35
for
(n = 0; n < C->
nclasses
; n++) {
36
I_new_signature
(&C->
S
);
37
}
38
39
for
(p = 0; p < C->
npoints
; p++) {
40
c = C->
class
[p];
41
if
(c < 0)
42
continue
;
43
/*
44
if (c >= C->nclasses)
45
fprintf (stderr, " class[%d]=%d ** illegal **\n", p, c);
46
*/
47
dn
= n = C->
count
[c];
48
if
(n < 2)
49
continue
;
50
for
(
band1
= 0;
band1
< C->
nbands
;
band1
++) {
51
m1 = C->
sum
[
band1
][c] /
dn
;
52
p1
= C->
points
[
band1
][p];
53
for
(
band2
= 0;
band2
<=
band1
;
band2
++) {
54
m2 = C->
sum
[
band2
][c] /
dn
;
55
p2 = C->
points
[
band2
][p];
56
C->
S
.sig[c].var[
band1
][
band2
] += (
p1
- m1) * (p2 - m2);
57
}
58
}
59
}
60
61
for
(c = 0; c < C->
nclasses
; c++) {
62
dn
= n = C->
S
.sig[c].npoints = C->
count
[c];
63
if
(n == 0)
64
dn
= 1.0;
65
for
(
band1
= 0;
band1
< C->
nbands
;
band1
++)
66
C->
S
.sig[c].mean[
band1
] = C->
sum
[
band1
][c] /
dn
;
67
dn
= n = C->
count
[c] - 1;
68
if
(n < 1)
69
continue
;
70
for
(
band1
= 0;
band1
< C->
nbands
;
band1
++)
71
for
(
band2
= 0;
band2
<=
band1
;
band2
++)
72
C->
S
.sig[c].var[
band1
][
band2
] /=
dn
;
73
C->
S
.sig[c].status = 1;
74
}
75
76
return
0;
77
}
I_cluster_signatures
int I_cluster_signatures(struct Cluster *C)
Create signatures.
Definition
c_sig.c:21
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 Tue Sep 15 2026 06:57:38 for GRASS 8 Programmer's Manual by
1.9.8