GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
c_sep.c
Go to the documentation of this file.
1/*!
2 \file cluster/c_sep.c
3
4 \brief Cluster library - Separation
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 <math.h>
13#include <grass/cluster.h>
14
15#define FAR ((double)-1.0)
16
17/*!
18 \brief ?
19
20 \param C pointer to Cluster structure
21 \param class1 1st class
22 \param class2 2nd class
23 */
24double I_cluster_separation(struct Cluster *C, int class1, int class2)
25{
26 int band;
27 double q;
28 double d;
29 double var;
30 double a1, a2;
31 double n1, n2;
32 double m1, m2;
33 double s1, s2;
34
35 if (C->count[class1] < 2)
36 return FAR;
37 if (C->count[class2] < 2)
38 return FAR;
39 n1 = (double)C->count[class1];
40 n2 = (double)C->count[class2];
41
42 d = 0.0;
43 a1 = a2 = 0.0;
44 for (band = 0; band < C->nbands; band++) {
45 s1 = C->sum[band][class1];
46 s2 = C->sum[band][class2];
47 m1 = s1 / n1;
48 m2 = s2 / n2;
49 q = m1 - m2;
50 q = q * q;
51 d += q;
52
53 var = C->sum2[band][class1] - (s1 * m1);
54 var /= n1 - 1;
55 if (var)
56 a1 += q / var;
57
58 var = C->sum2[band][class2] - (s2 * m2);
59 var /= n2 - 1;
60 if (var)
61 a2 += q / var;
62 }
63 if (d == 0.0)
64 return d;
65
66 if (a1 < 0 || a2 < 0)
67 return FAR;
68 if (a1)
69 a1 = sqrt(6 * d / a1);
70 if (a2)
71 a2 = sqrt(6 * d / a2);
72 q = a1 + a2;
73 if (q == 0.0)
74 return FAR;
75
76 return (sqrt(d) / q);
77}
#define FAR
Definition c_sep.c:15
double I_cluster_separation(struct Cluster *C, int class1, int class2)
?
Definition c_sep.c:24
float var(IClass_statistics *statistics, int band1, int band2)
Helper function for computing variance.
int * count
Definition cluster.h:18
double ** sum2
Definition cluster.h:22
double ** sum
Definition cluster.h:20
int nbands
Definition cluster.h:8