GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73570
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
iclass_statistics.c File Reference

Imagery library - functions for wx.iclass. More...

#include <math.h>
#include <grass/imagery.h>
#include <grass/glocale.h>
#include <grass/colors.h>
#include "iclass_local_proto.h"
Include dependency graph for iclass_statistics.c:

Go to the source code of this file.

Functions

void I_iclass_init_statistics (IClass_statistics *statistics, int category, const char *name, const char *color, float nstd)
 Initialize statistics. More...
 
void alloc_statistics (IClass_statistics *statistics, int nbands)
 Allocate space for statistics. More...
 
void I_iclass_free_statistics (IClass_statistics *statistics)
 Free space allocated for statistics attributes. More...
 
int make_all_statistics (IClass_statistics *statistics, IClass_perimeter_list *perimeters, CELL **band_buffer, int *band_fd)
 Calculate statistics for all training areas. More...
 
int make_statistics (IClass_statistics *statistics, IClass_perimeter *perimeter, CELL **band_buffer, int *band_fd)
 Calculate statistics for one training area. More...
 
void create_raster (IClass_statistics *statistics, CELL **band_buffer, int *band_fd, const char *raster_name)
 Create raster map based on statistics. More...
 
void band_range (IClass_statistics *statistics, int band)
 Helper function for computing min and max range in one band. More...
 
float mean (IClass_statistics *statistics, int band)
 Helper function for computing mean. More...
 
float stddev (IClass_statistics *statistics, int band)
 Helper function for standard deviation. More...
 
float var (IClass_statistics *statistics, int band1, int band2)
 Helper function for computing variance. More...
 
float var_signature (IClass_statistics *statistics, int band1, int band2)
 Helper function for computing variance for signature file. More...
 
void I_iclass_statistics_get_nbands (IClass_statistics *statistics, int *nbands)
 Get number of bands. More...
 
void I_iclass_statistics_get_cat (IClass_statistics *statistics, int *cat)
 Get category (class). More...
 
void I_iclass_statistics_get_name (IClass_statistics *statistics, const char **name)
 Get category (class) name. More...
 
void I_iclass_statistics_get_color (IClass_statistics *statistics, const char **color)
 Get category (class) color. More...
 
void I_iclass_statistics_get_ncells (IClass_statistics *statistics, int *ncells)
 Get number of cells in training areas. More...
 
void I_iclass_statistics_get_nstd (IClass_statistics *statistics, float *nstd)
 Get the multiplier of standard deviation. More...
 
void I_iclass_statistics_set_nstd (IClass_statistics *statistics, float nstd)
 Set the multiplier of standard deviation. More...
 
int I_iclass_statistics_get_min (IClass_statistics *statistics, int band, int *min)
 Get minimum value in band. More...
 
int I_iclass_statistics_get_max (IClass_statistics *statistics, int band, int *max)
 Get maximum value in band. More...
 
int I_iclass_statistics_get_sum (IClass_statistics *statistics, int band, float *sum)
 Get sum of values in band. More...
 
int I_iclass_statistics_get_mean (IClass_statistics *statistics, int band, float *mean)
 Get mean of cell category values in band. More...
 
int I_iclass_statistics_get_stddev (IClass_statistics *statistics, int band, float *stddev)
 Get standard deviation of cell category values in band. More...
 
int I_iclass_statistics_get_histo (IClass_statistics *statistics, int band, int cat, int *value)
 Get histogram value in band. More...
 
int I_iclass_statistics_get_product (IClass_statistics *statistics, int band1, int band2, float *value)
 Get product value. More...
 
int I_iclass_statistics_get_range_min (IClass_statistics *statistics, int band, int *min)
 Get minimum cell value based on mean and standard deviation for band. More...
 
int I_iclass_statistics_get_range_max (IClass_statistics *statistics, int band, int *max)
 Get maximum cell value based on mean and standard deviation for band. More...
 

Detailed Description

Imagery library - functions for wx.iclass.

Computation based on training areas for supervised classification. Based on i.class module (GRASS 6).

Computation and writing signatures to file.

Copyright (C) 1999-2007, 2011 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
David Satnik, Central Washington University (original author)
Markus Neteler <neteler itc.it> (i.class module)
Bernhard Reiter <bernhard intevation.de> (i.class module)
Brad Douglas <rez touchofmadness.com>(i.class module)
Glynn Clements <glynn gclements.plus.com> (i.class module)
Hamish Bowman <hamish_b yahoo.com> (i.class module)
Jan-Oliver Wagner <jan intevation.de> (i.class module)
Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)

Computation based on training areas for supervised classification. Based on i.class module (GRASS 6).

Computing statistical values (mean, min, max, ...) from given area perimeters for each band.

Copyright (C) 1999-2007, 2011 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
David Satnik, Central Washington University (original author)
Markus Neteler <neteler itc.it> (i.class module)
Bernhard Reiter <bernhard intevation.de> (i.class module)
Brad Douglas <rez touchofmadness.com>(i.class module)
Glynn Clements <glynn gclements.plus.com> (i.class module)
Hamish Bowman <hamish_b yahoo.com> (i.class module)
Jan-Oliver Wagner <jan intevation.de> (i.class module)
Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)

Definition in file iclass_statistics.c.

Function Documentation

void alloc_statistics ( IClass_statistics statistics,
int  nbands 
)
void band_range ( IClass_statistics statistics,
int  band 
)

Helper function for computing min and max range in one band.

Computing min and max range value (distance from mean dependent on number od std ddevs).

Parameters
statisticspointer to statistics structure
bandband index

Definition at line 350 of file iclass_statistics.c.

References IClass_statistics::band_mean, IClass_statistics::band_range_max, IClass_statistics::band_range_min, IClass_statistics::band_stddev, and IClass_statistics::nstd.

Referenced by I_iclass_create_raster(), and make_all_statistics().

void create_raster ( IClass_statistics statistics,
CELL **  band_buffer,
int band_fd,
const char *  raster_name 
)

Create raster map based on statistics.

Parameters
statisticspointer to statistics structure
band_bufferbuffer to read band rows into
band_fdband files descriptors
raster_namename of new raster map

Definition at line 282 of file iclass_statistics.c.

References b, IClass_statistics::band_range_max, IClass_statistics::band_range_min, CELL_TYPE, IClass_statistics::color, fd, g, G_mapset(), G_str_to_color(), IClass_statistics::nbands, r, Rast_allocate_c_buf(), Rast_close(), Rast_init_colors(), Rast_open_c_new(), Rast_put_row(), Rast_set_c_color(), Rast_window_cols(), Rast_window_rows(), Rast_write_colors(), and read_band_row().

Referenced by I_iclass_analysis(), and I_iclass_create_raster().

void I_iclass_free_statistics ( IClass_statistics statistics)
void I_iclass_init_statistics ( IClass_statistics statistics,
int  category,
const char *  name,
const char *  color,
float  nstd 
)
void I_iclass_statistics_get_cat ( IClass_statistics statistics,
int cat 
)

Get category (class).

Parameters
statisticspointer to statistics structure
[out]catcategory

Definition at line 475 of file iclass_statistics.c.

References IClass_statistics::cat.

void I_iclass_statistics_get_color ( IClass_statistics statistics,
const char **  color 
)

Get category (class) color.

Note
color is pointer to already allocated const char * in statistics. You should not free it.
Parameters
statisticspointer to statistics structure
[out]colorcategory color

Definition at line 506 of file iclass_statistics.c.

References IClass_statistics::color.

int I_iclass_statistics_get_histo ( IClass_statistics statistics,
int  band,
int  cat,
int value 
)

Get histogram value in band.

Each band has one value for each raster cell category. Value is number of cells in category.

Parameters
statisticspointer to statistics structure
bandband index
catraster cell category
[out]valuenumber of cells in category
Returns
1 on success
0 band index or cell category value out of range

Definition at line 676 of file iclass_statistics.c.

References _, IClass_statistics::band_histo, cat, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_max ( IClass_statistics statistics,
int  band,
int max 
)

Get maximum value in band.

Parameters
statisticspointer to statistics structure
bandband index
[out]maxmaximum value
Returns
1 on success
0 band index out of range

Definition at line 580 of file iclass_statistics.c.

References _, IClass_statistics::band_max, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_mean ( IClass_statistics statistics,
int  band,
float *  mean 
)

Get mean of cell category values in band.

Parameters
statisticspointer to statistics structure
bandband index
[out]meanmean
Returns
1 on success
0 band index out of range

Definition at line 626 of file iclass_statistics.c.

References _, IClass_statistics::band_mean, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_min ( IClass_statistics statistics,
int  band,
int min 
)

Get minimum value in band.

Parameters
statisticspointer to statistics structure
bandband index
[out]minminimum value
Returns
1 on success
0 band index out of range

Definition at line 557 of file iclass_statistics.c.

References _, IClass_statistics::band_min, G_warning(), and IClass_statistics::nbands.

void I_iclass_statistics_get_name ( IClass_statistics statistics,
const char **  name 
)

Get category (class) name.

Note
name is pointer to already allocated const char * in statistics. You should not free it.
Parameters
statisticspointer to statistics structure
[out]namecategory name

Definition at line 490 of file iclass_statistics.c.

References IClass_statistics::name.

void I_iclass_statistics_get_nbands ( IClass_statistics statistics,
int nbands 
)

Get number of bands.

Parameters
statisticspointer to statistics structure
[out]nbandsnumber of bands

Definition at line 463 of file iclass_statistics.c.

References IClass_statistics::nbands.

void I_iclass_statistics_get_ncells ( IClass_statistics statistics,
int ncells 
)

Get number of cells in training areas.

Parameters
statisticspointer to statistics structure
[out]ncellsnumber of cells

Definition at line 519 of file iclass_statistics.c.

References IClass_statistics::ncells.

void I_iclass_statistics_get_nstd ( IClass_statistics statistics,
float *  nstd 
)

Get the multiplier of standard deviation.

Parameters
statisticspointer to statistics structure
[out]nstdmultiplier of standard deviation

Definition at line 531 of file iclass_statistics.c.

References IClass_statistics::nstd.

int I_iclass_statistics_get_product ( IClass_statistics statistics,
int  band1,
int  band2,
float *  value 
)

Get product value.

Product value of two bands is sum of products of cell category values of two bands. Only cells from training areas are taken into account.

Parameters
statisticsstatistics object
band1index of first band
band2index of second band
[out]valueproduct value
Returns
1 on success
0 band index out of range

Definition at line 708 of file iclass_statistics.c.

References _, IClass_statistics::band_product, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_range_max ( IClass_statistics statistics,
int  band,
int max 
)

Get maximum cell value based on mean and standard deviation for band.

Parameters
statisticspointer to statistics structure
bandband index
[out]maxmaximum value
Returns
1 on success
0 band index out of range

Definition at line 754 of file iclass_statistics.c.

References _, IClass_statistics::band_range_max, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_range_min ( IClass_statistics statistics,
int  band,
int min 
)

Get minimum cell value based on mean and standard deviation for band.

Parameters
statisticspointer to statistics structure
bandband index
[out]minminimum value
Returns
1 on success
0 band index out of range

Definition at line 731 of file iclass_statistics.c.

References _, IClass_statistics::band_range_min, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_stddev ( IClass_statistics statistics,
int  band,
float *  stddev 
)

Get standard deviation of cell category values in band.

Parameters
statisticspointer to statistics structure
bandband index
[out]stddevstandard deviation
Returns
1 on success
0 band index out of range

Definition at line 649 of file iclass_statistics.c.

References _, IClass_statistics::band_stddev, G_warning(), and IClass_statistics::nbands.

int I_iclass_statistics_get_sum ( IClass_statistics statistics,
int  band,
float *  sum 
)

Get sum of values in band.

Parameters
statisticspointer to statistics structure
bandband index
[out]sumsum
Returns
1 on success
0 band index out of range

Definition at line 603 of file iclass_statistics.c.

References _, IClass_statistics::band_sum, G_warning(), and IClass_statistics::nbands.

void I_iclass_statistics_set_nstd ( IClass_statistics statistics,
float  nstd 
)

Set the multiplier of standard deviation.

Parameters
statisticspointer to statistics structure
nstdmultiplier of standard deviation

Definition at line 542 of file iclass_statistics.c.

References IClass_statistics::nstd.

int make_all_statistics ( IClass_statistics statistics,
IClass_perimeter_list *  perimeters,
CELL **  band_buffer,
int band_fd 
)

Calculate statistics for all training areas.

Parameters
statisticspointer to statistics structure
perimeterslist of all area perimeters
band_bufferbuffer to read band rows into
band_fdband files descriptors
Returns
1 on succes
0 on failure

Definition at line 144 of file iclass_statistics.c.

References b, IClass_statistics::band_histo, IClass_statistics::band_max, IClass_statistics::band_mean, IClass_statistics::band_min, IClass_statistics::band_product, band_range(), IClass_statistics::band_stddev, IClass_statistics::band_sum, for(), G_debug(), make_statistics(), mean(), IClass_statistics::nbands, and stddev().

Referenced by I_iclass_analysis().

int make_statistics ( IClass_statistics statistics,
IClass_perimeter *  perimeter,
CELL **  band_buffer,
int band_fd 
)

Calculate statistics for one training area.

Parameters
[out]statisticspointer to statistics structure
perimeterarea perimeter
band_bufferbuffer to read band rows into
band_fdband files descriptors
Returns
1 on succes
0 on failure

Definition at line 195 of file iclass_statistics.c.

References _, b, IClass_statistics::band_histo, IClass_statistics::band_max, IClass_statistics::band_min, IClass_statistics::band_product, IClass_statistics::band_sum, G_debug(), G_warning(), IClass_statistics::nbands, IClass_statistics::ncells, read_band_row(), x, and line_pnts::y.

Referenced by make_all_statistics().

float mean ( IClass_statistics statistics,
int  band 
)
float stddev ( IClass_statistics statistics,
int  band 
)

Helper function for standard deviation.

Computing standard deviation of cell category values in one band within training area.

Parameters
statisticspointer to statistics structure
bandband index
Returns
standard deviation

Definition at line 388 of file iclass_statistics.c.

References var().

Referenced by make_all_statistics().

float var ( IClass_statistics statistics,
int  band1,
int  band2 
)

Helper function for computing variance.

Computing variance of cell category values in one band within training area.

Parameters
statisticspointer to statistics structure
band1band index
band2band index
Returns
variance
See Also
var_signature

Definition at line 407 of file iclass_statistics.c.

References IClass_statistics::band_product, mean(), and IClass_statistics::ncells.

Referenced by c_kurt(), c_stddev(), I_cluster_separation(), stddev(), w_kurt(), and w_stddev().

float var_signature ( IClass_statistics statistics,
int  band1,
int  band2 
)

Helper function for computing variance for signature file.

Computing variance of cell category values in one band within training area. Variance is computed in special way.

Parameters
statisticspointer to statistics structure
band1band index
band2band index
Returns
variance
See Also
var
Todo:
verify the computation

Definition at line 440 of file iclass_statistics.c.

References IClass_statistics::band_product, IClass_statistics::band_sum, and IClass_statistics::ncells.

Referenced by I_iclass_add_signature().