2
/****************************************************************************
5
* AUTHOR(S): Eric Momsen <eric.momsen at gmail com>
6
* PURPOSE: structure definition and function listing
7
* COPYRIGHT: (C) 2012 by Eric Momsen, and the GRASS Development Team
9
* This program is free software under the GNU General Public
10
* License (>=v2). Read the COPYING file that comes with GRASS
13
*****************************************************************************/
15
#include <grass/segment.h>
33
struct rc *tail, *head;
36
/* input and output files, as well as some other processing info */
41
int weighted; /* 0 if false/not selected, so we should scale input.
42
* 1 if the scaling should be skipped */
43
int method; /* Segmentation method */
44
int nn; /* number of neighbors, 4 or 8 */
45
double max_diff; /* max possible difference */
46
double alpha; /* similarity threshold */
47
int min_segment_size; /* smallest number of pixels/cells allowed in a final segment */
49
double radio_weight; /* weighing factor radiometric - shape */
50
double smooth_weight; /* weighing factor smoothness - compactness */
52
int end_t; /* maximum number of iterations */
57
int row_min, row_max, col_min, col_max; /* region constraints */
58
long ncells, notnullcells;
60
char *out_name; /* name of output raster map */
61
char *seeds, *bounds_map; /* optional segment seeds and polygon constraints/boundaries */
62
CELL lower_bound, upper_bound;
63
const char *bounds_mapset;
64
char *out_band; /* indicator for segment heterogeneity */
67
int nbands; /* number of rasters in the image group */
68
SEGMENT bands_seg, /* input group with one or more bands */
71
DCELL *bands_min, *bands_max;
72
DCELL *bands_val; /* array to hold all input values for one cell */
73
DCELL *second_val; /* array to hold all input values for another cell */
76
struct RG_TREE *reg_tree; /* search tree with region stats */
77
int min_reg_size; /* minimum region size */
78
struct reg_stats rs, rs_i, rs_k;
80
size_t datasize; /* nbands * sizeof(double) */
83
/* processing flags */
84
FLAG *candidate_flag, *null_flag; /*TODO, need some way to remember MASK/NULL values. Was using -1, 0, 1 in int array. Better to use 2 FLAG structures, better readibility? */
86
/* number of remaining cells to check */
91
void (*find_neighbors) (int, int, int[8][2]); /*parameters: row, col, neighbors */
92
double (*calculate_similarity) (struct ngbr_stats *,
94
struct globals *); /*parameters: two regions to compare */
99
/* gets input from user, validates, and sets up functions */
100
int parse_args(int, char *[], struct globals *);
103
int open_files(struct globals *);
106
int create_isegs(struct globals *);
107
int region_growing(struct globals *);
108
void find_four_neighbors(int, int, int[][2]);
109
void find_eight_neighbors(int, int, int[8][2]);
110
double calculate_euclidean_similarity(struct ngbr_stats *,
113
double calculate_manhattan_similarity(struct ngbr_stats *,
116
double calculate_shape(struct reg_stats *, struct reg_stats *,
117
int, struct globals *);
118
int fetch_reg_stats(int , int , struct reg_stats *,
120
int update_band_vals(int, int, struct reg_stats *, struct globals *);
122
/* void calculate_reg_stats(int, int, struct reg_stats *,
123
struct globals *); */
127
void rclist_init(struct rclist *);
128
void rclist_add(struct rclist *, int, int);
129
int rclist_drop(struct rclist *, struct rc *);
130
void rclist_destroy(struct rclist *);
134
int write_output(struct globals *);
135
int close_files(struct globals *);