6 static int gettag(FILE *,
char *);
7 static int get_nbands(FILE *,
struct SigSet *);
8 static int get_title(FILE *,
struct SigSet *);
9 static int get_class(FILE *,
struct SigSet *);
10 static int get_classnum(FILE *,
struct ClassSig *);
11 static int get_classtype(FILE *,
struct ClassSig *);
12 static int get_classtitle(FILE *,
struct ClassSig *);
13 static int get_subclass(FILE *,
struct SigSet *,
struct ClassSig *);
14 static int get_subclass_pi(FILE *,
struct SubSig *);
15 static int get_subclass_means(FILE *,
struct SubSig *,
int);
16 static int get_subclass_covar(FILE *,
struct SubSig *,
int);
18 static double **alloc_matrix(
int rows,
int cols)
23 m = (
double **)
G_calloc(rows,
sizeof(
double *));
24 m[0] = (
double *)
G_calloc(rows * cols,
sizeof(
double));
25 for (i = 1; i < rows; i++)
26 m[i] = m[i - 1] + cols;
35 for (i = 0, count = 0; i < S->
nclasses; i++)
51 Data->
x = alloc_matrix(npixels, S->
nbands);
109 for (i = 1; i < S->
nbands; i++)
110 Sp->
R[i] = Sp->
R[i - 1] + S->
nbands;
113 for (i = 1; i < S->
nbands; i++)
122 #define eq(a,b) strcmp(a,b)==0 130 while (gettag(fd, tag)) {
131 if (
eq(tag,
"title:"))
132 if (get_title(fd, S) != 0)
134 if (
eq(tag,
"nbands:"))
135 if (get_nbands(fd, S) != 0)
137 if (
eq(tag,
"class:"))
138 if (get_class(fd, S) != 0)
144 static int gettag(FILE * fd,
char *tag)
146 if (fscanf(fd,
"%s", tag) != 1)
152 static int get_nbands(FILE * fd,
struct SigSet *S)
154 if (fscanf(fd,
"%d", &S->
nbands) != 1)
160 static int get_title(FILE * fd,
struct SigSet *S)
165 if (fscanf(fd,
"%[^\n]", title) != 1)
172 static int get_class(FILE * fd,
struct SigSet *S)
178 while (gettag(fd, tag)) {
179 if (
eq(tag,
"endclass:"))
181 if (
eq(tag,
"classnum:"))
182 if (get_classnum(fd, C) != 0)
184 if (
eq(tag,
"classtype:"))
185 if (get_classtype(fd, C) != 0)
187 if (
eq(tag,
"classtitle:"))
188 if (get_classtitle(fd, C) != 0)
190 if (
eq(tag,
"subclass:"))
191 if (get_subclass(fd, S, C) != 0)
198 static int get_classnum(FILE * fd,
struct ClassSig *C)
200 if (fscanf(fd,
"%ld", &C->
classnum) != 1)
206 static int get_classtype(FILE * fd,
struct ClassSig *C)
208 if (fscanf(fd,
"%d", &C->
type) != 1)
214 static int get_classtitle(FILE * fd,
struct ClassSig *C)
219 if (fscanf(fd,
"%[^\n]", title) != 1)
226 static int get_subclass(FILE * fd,
struct SigSet *S,
struct ClassSig *C)
233 while (gettag(fd, tag)) {
234 if (
eq(tag,
"endsubclass:"))
237 if (get_subclass_pi(fd, Sp) != 0)
239 if (
eq(tag,
"means:"))
240 if (get_subclass_means(fd, Sp, S->
nbands) != 0)
242 if (
eq(tag,
"covar:"))
243 if (get_subclass_covar(fd, Sp, S->
nbands) != 0)
250 static int get_subclass_pi(FILE * fd,
struct SubSig *Sp)
252 if (fscanf(fd,
"%lf", &Sp->
pi) != 1)
258 static int get_subclass_means(FILE * fd,
struct SubSig *Sp,
int nbands)
262 for (i = 0; i < nbands; i++)
263 if (fscanf(fd,
"%lf", &Sp->
means[i]) != 1)
269 static int get_subclass_covar(FILE * fd,
struct SubSig *Sp,
int nbands)
273 for (i = 0; i < nbands; i++)
274 for (j = 0; j < nbands; j++)
275 if (fscanf(fd,
"%lf", &Sp->
R[i][j]) != 1)
326 fprintf(fd,
"nbands: %d\n", S->
nbands);
333 fprintf(fd,
"class:\n");
334 fprintf(fd,
" classnum: %ld\n", Cp->
classnum);
336 fprintf(fd,
" classtype: %d\n", Cp->
type);
340 fprintf(fd,
" subclass:\n");
341 fprintf(fd,
" pi: %g\n", Sp->
pi);
342 fprintf(fd,
" means:");
343 for (b1 = 0; b1 < S->
nbands; b1++)
344 fprintf(fd,
" %g", Sp->
means[b1]);
346 fprintf(fd,
" covar:\n");
347 for (b1 = 0; b1 < S->
nbands; b1++) {
349 for (b2 = 0; b2 < S->
nbands; b2++)
350 fprintf(fd,
" %g", Sp->
R[b1][b2]);
353 fprintf(fd,
" endsubclass:\n");
355 fprintf(fd,
"endclass:\n");
const char * I_GetSigTitle(const struct SigSet *S)
#define SIGNATURE_TYPE_MIXED
int I_InitSigSet(struct SigSet *S)
void G_strip(char *)
Removes all leading and trailing white space from string.
int I_SetClassTitle(struct ClassSig *C, const char *title)
int I_SetSigTitle(struct SigSet *S, const char *title)
struct ClassSig * I_NewClassSig(struct SigSet *S)
struct ClassSig * ClassSig
int I_SigSetNClasses(struct SigSet *S)
struct ClassData * I_AllocClassData(struct SigSet *S, struct ClassSig *C, int npixels)
int I_WriteSigSet(FILE *fd, const struct SigSet *S)
int I_SigSetNBands(struct SigSet *S, int nbands)
struct SubSig * I_NewSubSig(struct SigSet *S, struct ClassSig *C)
char * G_store(const char *)
Copy string to allocated memory.
int I_ReadSigSet(FILE *fd, struct SigSet *S)
const char * I_GetClassTitle(const struct ClassSig *C)
struct ClassData ClassData