7static int gettag(
FILE *,
char *);
8static int get_semantic_labels(
FILE *,
struct SigSet *);
15static int get_subclass_pi(
FILE *,
struct SubSig *);
16static int get_subclass_means(
FILE *,
struct SubSig *,
int);
17static int get_subclass_covar(
FILE *,
struct SubSig *,
int);
19static double **alloc_matrix(
int rows,
int cols)
24 m = (
double **)
G_calloc(rows,
sizeof(
double *));
25 m[0] = (
double *)
G_calloc(rows * cols,
sizeof(
double));
26 for (i = 1; i < rows; i++)
27 m[i] =
m[i - 1] + cols;
68 for (
int i = 0; i < nbands; i++)
111 for (i = 1; i < S->
nbands; i++)
115 for (i = 1; i < S->
nbands; i++)
124#define eq(a, b) strcmp(a, b) == 0
144 unsigned int version;
146 if (
fscanf(fd,
"%u", &version) != 1) {
151 G_warning(
_(
"Invalid signature file version"));
156 while (gettag(fd,
tag)) {
157 if (
eq(
tag,
"title:"))
158 if (get_title(fd, S) != 0)
160 if (
eq(
tag,
"semantic_labels:"))
161 if (get_semantic_labels(fd, S) != 0)
163 if (
eq(
tag,
"class:"))
164 if (get_class(fd, S) != 0)
170static int gettag(
FILE *fd,
char *
tag)
178static int get_semantic_labels(
FILE *fd,
struct SigSet *S)
189 while ((c = (
char)
fgetc(fd)) !=
EOF) {
217 G_warning(
_(
"Invalid signature file: semantic label length limit "
226 G_warning(
_(
"Signature file does not contain bands"));
233static int get_title(
FILE *fd,
struct SigSet *S)
238 if (
fscanf(fd,
"%1023[^\n]", title) != 1)
246static int get_class(
FILE *fd,
struct SigSet *S)
252 while (gettag(fd,
tag)) {
253 if (
eq(
tag,
"endclass:"))
255 if (
eq(
tag,
"classnum:"))
256 if (get_classnum(fd, C) != 0)
258 if (
eq(
tag,
"classtype:"))
259 if (get_classtype(fd, C) != 0)
261 if (
eq(
tag,
"classtitle:"))
262 if (get_classtitle(fd, C) != 0)
264 if (
eq(
tag,
"subclass:"))
265 if (get_subclass(fd, S, C) != 0)
308 while (gettag(fd,
tag)) {
309 if (
eq(
tag,
"endsubclass:"))
312 if (get_subclass_pi(fd,
Sp) != 0)
314 if (
eq(
tag,
"means:"))
315 if (get_subclass_means(fd,
Sp, S->
nbands) != 0)
317 if (
eq(
tag,
"covar:"))
318 if (get_subclass_covar(fd,
Sp, S->
nbands) != 0)
327 if (
fscanf(fd,
"%lf", &
Sp->pi) != 1)
333static int get_subclass_means(
FILE *fd,
struct SubSig *
Sp,
int nbands)
337 for (i = 0; i < nbands; i++)
338 if (
fscanf(fd,
"%lf", &
Sp->means[i]) != 1)
344static int get_subclass_covar(
FILE *fd,
struct SubSig *
Sp,
int nbands)
348 for (i = 0; i < nbands; i++)
349 for (
j = 0;
j < nbands;
j++)
350 if (
fscanf(fd,
"%lf", &
Sp->R[i][
j]) != 1)
403 fprintf(fd,
"semantic_labels: ");
404 for (i = 0; i < S->
nbands; i++) {
412 if (
Cp->nsubclasses <= 0)
415 fprintf(fd,
" classnum: %ld\n",
Cp->classnum);
417 fprintf(fd,
" classtype: %d\n",
Cp->type);
419 for (
j = 0;
j <
Cp->nsubclasses;
j++) {
434 fprintf(fd,
" endsubclass:\n");
484 if (S->
nbands < 1 ||
R->nfiles < 1)
485 G_fatal_error(
"Programming error. Invalid length structs passed to "
486 "I_sort_signatures_by_semantic_label(%d, %d);",
491 for (
unsigned int j =
R->nfiles;
j--;) {
509 for (
unsigned int c = S->
nclasses; c--;) {
514 for (
unsigned int s = S->
ClassSig[c].nsubclasses; s--;) {
517 for (
unsigned int i = S->
nbands; i--;)
524 for (
unsigned int j =
R->nfiles;
j--;) {
525 for (
unsigned int i = S->
nbands; i--;) {
547 for (
unsigned int i = 0; i < (
unsigned int)S->
nbands; i++) {
568 for (
unsigned int j = 0;
j < (
unsigned int)
R->nfiles;
j++) {
591 for (
unsigned int c = S->
nclasses; c--;) {
592 for (
unsigned int s = S->
ClassSig[c].nsubclasses; s--;) {
607 S->
nbands *
sizeof(
char **));
608 for (
unsigned int c = S->
nclasses; c--;) {
609 for (
unsigned int s = S->
ClassSig[c].nsubclasses; s--;) {
611 S->
nbands *
sizeof(
double));
612 for (
unsigned int i = S->
nbands; i--;)
614 S->
nbands *
sizeof(
double));
620 for (
unsigned int j =
R->nfiles;
j--;)
627 for (
unsigned int c = S->
nclasses; c--;) {
628 for (
unsigned int s = S->
ClassSig[c].nsubclasses; s--;) {
630 for (
unsigned int i = S->
nbands; i--;)
AMI_err name(char **stream_name)
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_strip(char *)
Removes all leading and trailing white space from string.
char * G_store(const char *)
Copy string to allocated memory.
char * Rast_get_semantic_label_or_name(const char *, const char *)
Get a raster map semantic label or fall back to its name.
#define SIGNATURE_TYPE_MIXED
struct SubSig * I_NewSubSig(struct SigSet *S, struct ClassSig *C)
int I_SetSigTitle(struct SigSet *S, const char *title)
int I_ReadSigSet(FILE *fd, struct SigSet *S)
Read sigset signatures from file.
int I_SigSetNClasses(struct SigSet *S)
int I_SetClassTitle(struct ClassSig *C, const char *title)
const char * I_GetSigTitle(const struct SigSet *S)
char ** I_SortSigSetBySemanticLabel(struct SigSet *S, const struct Ref *R)
Reorder struct SigSet to match imagery group member order.
int I_InitSigSet(struct SigSet *S, int nbands)
Initialize struct SigSet before use.
struct ClassSig * I_NewClassSig(struct SigSet *S)
struct ClassData * I_AllocClassData(struct SigSet *S, struct ClassSig *C, int npixels)
const char * I_GetClassTitle(const struct ClassSig *C)
int I_WriteSigSet(FILE *fd, const struct SigSet *S)
struct ClassData ClassData
struct ClassSig * ClassSig