~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to lib/imagery/iclass_signatures.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
   \file lib/imagery/iclass_statistics.c
 
3
 
 
4
   \brief Imagery library - functions for wx.iclass
 
5
 
 
6
   Computation based on training areas for supervised classification.
 
7
   Based on i.class module (GRASS 6).
 
8
 
 
9
   Computation and writing signatures to file.
 
10
 
 
11
   Copyright (C) 1999-2007, 2011 by the GRASS Development Team
 
12
 
 
13
   This program is free software under the GNU General Public License
 
14
   (>=v2).  Read the file COPYING that comes with GRASS for details.
 
15
 
 
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)
 
25
 */
 
26
 
 
27
#include <string.h>
 
28
#include <stdio.h>
 
29
 
 
30
#include <grass/imagery.h>
 
31
#include <grass/glocale.h>
 
32
#include <grass/colors.h>
 
33
 
 
34
#include "iclass_local_proto.h"
 
35
 
 
36
 
 
37
 
 
38
/*!
 
39
   \brief Initialize signatures.
 
40
 
 
41
   \param[out] sigs pointer to signatures
 
42
   \param refer pointer to band files structure
 
43
 
 
44
   \return 1 on success
 
45
   \return 0 on failure
 
46
 */
 
47
int I_iclass_init_signatures(struct Signature *sigs, struct Ref *refer)
 
48
{
 
49
    G_debug(3, "I_iclass_init_signatures()");
 
50
 
 
51
    if (!I_init_signatures(sigs, refer->nfiles))
 
52
        return 1;               /* success */
 
53
 
 
54
    return 0;
 
55
}
 
56
 
 
57
/*!
 
58
   \brief Add one signature.
 
59
 
 
60
   \param[out] sigs pointer to signatures
 
61
   \param statistics pointer to statistics structure
 
62
 */
 
63
void I_iclass_add_signature(struct Signature *sigs,
 
64
                            IClass_statistics * statistics)
 
65
{
 
66
    int sn;
 
67
 
 
68
    int b1, b2;
 
69
 
 
70
    int r, g, b;
 
71
 
 
72
    G_debug(3, "I_iclass_add_signature()");
 
73
 
 
74
    G_str_to_color(statistics->color, &r, &g, &b);
 
75
 
 
76
    /* get a new signature */
 
77
    I_new_signature(sigs);
 
78
 
 
79
    /* save the signature in a Sig structure */
 
80
    sn = sigs->nsigs;
 
81
    strcpy(sigs->sig[sn - 1].desc, statistics->name);
 
82
    sigs->sig[sn - 1].npoints = statistics->ncells;
 
83
    sigs->sig[sn - 1].status = 1;
 
84
 
 
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;
 
89
 
 
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);
 
94
        }
 
95
    }
 
96
}
 
97
 
 
98
/*!
 
99
   \brief Write signtures to signature file.
 
100
 
 
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
 
105
 
 
106
   \return 1 on success
 
107
   \return 0 on failure
 
108
 */
 
109
int I_iclass_write_signatures(struct Signature *sigs, const char *group,
 
110
                              const char *sub_group, const char *file_name)
 
111
{
 
112
    FILE *outsig_fd;
 
113
 
 
114
    G_debug(3, "I_write_signatures(): group=%s, file_name=%s", group,
 
115
            file_name);
 
116
 
 
117
    if (!
 
118
        (outsig_fd =
 
119
         I_fopen_signature_file_new(group, sub_group, file_name))) {
 
120
        G_warning(_("Unable to open output signature file '%s'"), file_name);
 
121
        return 0;
 
122
    }
 
123
 
 
124
    I_write_signatures(outsig_fd, sigs);
 
125
    fclose(outsig_fd);
 
126
 
 
127
    return 1;
 
128
}