GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-0824e8842e
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

◆ alloc_statistics()

void alloc_statistics ( IClass_statistics statistics,
int  nbands 
)

◆ band_range()

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 349 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().

◆ create_raster()

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 281 of file iclass_statistics.c.

Referenced by I_iclass_analysis(), and I_iclass_create_raster().

◆ I_iclass_free_statistics()

void I_iclass_free_statistics ( IClass_statistics statistics)

◆ I_iclass_init_statistics()

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

◆ I_iclass_statistics_get_cat()

void I_iclass_statistics_get_cat ( IClass_statistics statistics,
int *  cat 
)

Get category (class).

Parameters
statisticspointer to statistics structure
[out]catcategory

Definition at line 471 of file iclass_statistics.c.

References IClass_statistics::cat.

◆ I_iclass_statistics_get_color()

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 502 of file iclass_statistics.c.

References IClass_statistics::color.

◆ I_iclass_statistics_get_histo()

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 670 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_max()

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 574 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_mean()

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 620 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_min()

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 551 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_name()

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 486 of file iclass_statistics.c.

References IClass_statistics::name, and name.

◆ I_iclass_statistics_get_nbands()

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 460 of file iclass_statistics.c.

References IClass_statistics::nbands.

◆ I_iclass_statistics_get_ncells()

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 514 of file iclass_statistics.c.

References IClass_statistics::ncells.

◆ I_iclass_statistics_get_nstd()

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 525 of file iclass_statistics.c.

References IClass_statistics::nstd.

◆ I_iclass_statistics_get_product()

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 702 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_range_max()

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 748 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_range_min()

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 725 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_stddev()

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 643 of file iclass_statistics.c.

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

◆ I_iclass_statistics_get_sum()

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 597 of file iclass_statistics.c.

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

◆ I_iclass_statistics_set_nstd()

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 536 of file iclass_statistics.c.

References IClass_statistics::nstd.

◆ make_all_statistics()

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 success
0 on failure

Definition at line 142 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, G_debug(), make_statistics(), mean(), IClass_statistics::nbands, and stddev().

Referenced by I_iclass_analysis().

◆ make_statistics()

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 success
0 on failure

Definition at line 193 of file iclass_statistics.c.

References b.

Referenced by make_all_statistics().

◆ mean()

float mean ( IClass_statistics statistics,
int  band 
)

Helper function for computing mean.

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

Parameters
statisticspointer to statistics structure
bandband index
Returns
mean value

Definition at line 369 of file iclass_statistics.c.

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

Referenced by Cdhc_anderson_darling(), Cdhc_anderson_darling_exp(), Cdhc_chi_square(), Cdhc_chi_square_exp(), Cdhc_cramer_von_mises(), Cdhc_cramer_von_mises_exp(), Cdhc_dmax(), Cdhc_dmax_exp(), Cdhc_omnibus_moments(), Cdhc_shapiro_wilk_exp(), Cdhc_watson_u2(), Cdhc_watson_u2_exp(), I_iclass_statistics_get_mean(), make_all_statistics(), N_compute_gradient_field_2d(), N_compute_gradient_field_3d(), P_Mean_Calc(), and var().

◆ stddev()

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 385 of file iclass_statistics.c.

References var().

Referenced by I_iclass_statistics_get_stddev(), and make_all_statistics().

◆ var()

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 404 of file iclass_statistics.c.

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

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

◆ var_signature()

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 437 of file iclass_statistics.c.

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

Referenced by I_iclass_add_signature().