2
\file lib/imagery/iclass_statistics.c
4
\brief Imagery library - functions for wx.iclass
6
Computation based on training areas for supervised classification.
7
Based on i.class module (GRASS 6).
9
Computation and writing signatures to file.
11
Copyright (C) 1999-2007, 2011 by the GRASS Development Team
13
This program is free software under the GNU General Public License
14
(>=v2). Read the file COPYING that comes with GRASS for details.
16
\author David Satnik, Central Washington University (original author)
17
\author Markus Neteler <neteler itc.it> (i.class module)
18
\author Bernhard Reiter <bernhard intevation.de> (i.class module)
19
\author Brad Douglas <rez touchofmadness.com>(i.class module)
20
\author Glynn Clements <glynn gclements.plus.com> (i.class module)
21
\author Hamish Bowman <hamish_b yahoo.com> (i.class module)
22
\author Jan-Oliver Wagner <jan intevation.de> (i.class module)
23
\author Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
24
\author Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)
30
#include <grass/imagery.h>
31
#include <grass/glocale.h>
32
#include <grass/colors.h>
34
#include "iclass_local_proto.h"
39
\brief Initialize signatures.
41
\param[out] sigs pointer to signatures
42
\param refer pointer to band files structure
47
int I_iclass_init_signatures(struct Signature *sigs, struct Ref *refer)
49
G_debug(3, "I_iclass_init_signatures()");
51
if (!I_init_signatures(sigs, refer->nfiles))
52
return 1; /* success */
58
\brief Add one signature.
60
\param[out] sigs pointer to signatures
61
\param statistics pointer to statistics structure
63
void I_iclass_add_signature(struct Signature *sigs,
64
IClass_statistics * statistics)
72
G_debug(3, "I_iclass_add_signature()");
74
G_str_to_color(statistics->color, &r, &g, &b);
76
/* get a new signature */
77
I_new_signature(sigs);
79
/* save the signature in a Sig structure */
81
strcpy(sigs->sig[sn - 1].desc, statistics->name);
82
sigs->sig[sn - 1].npoints = statistics->ncells;
83
sigs->sig[sn - 1].status = 1;
85
sigs->sig[sn - 1].have_color = 1;
86
sigs->sig[sn - 1].r = r;
87
sigs->sig[sn - 1].g = g;
88
sigs->sig[sn - 1].b = b;
90
for (b1 = 0; b1 < sigs->nbands; b1++) {
91
sigs->sig[sn - 1].mean[b1] = statistics->band_mean[b1];
92
for (b2 = 0; b2 <= b1; b2++) {
93
sigs->sig[sn - 1].var[b1][b2] = var_signature(statistics, b1, b2);
99
\brief Write signtures to signature file.
101
\param sigs pointer to signatures
102
\param group image group
103
\param sub_group image subgroup
104
\param file_name name of signature file
109
int I_iclass_write_signatures(struct Signature *sigs, const char *group,
110
const char *sub_group, const char *file_name)
114
G_debug(3, "I_write_signatures(): group=%s, file_name=%s", group,
119
I_fopen_signature_file_new(group, sub_group, file_name))) {
120
G_warning(_("Unable to open output signature file '%s'"), file_name);
124
I_write_signatures(outsig_fd, sigs);