00001 /* 00002 * Name: segment_modelset.h 00003 * 00004 * Include file for model sets used for image segmentation 00005 * 00006 * No code changes are needed to define a new modelset. You can do so 00007 * either in the .c file, to statically allocate it, or in a JSON format file 00008 * that you name. See the .c file for more on how this works. 00009 * 00010 * Michael Turmon, JPL 00011 * created 6/2011 00012 * 00013 */ 00014 00015 #ifndef _segment_modelset_h_ 00016 #define _segment_modelset_h_ 00017 00018 #include <string.h> 00019 #include <stdio.h> 00020 #include <stdlib.h> 00021 #include <stdarg.h> 00022 #include <sys/stat.h> 00023 // JSON structure parsing: see http://sourceforge.net/projects/cjson/ 00024 // #include "cJSON.h" 00025 00026 // name field starts this way for a builtin model 00027 #define SEG_BUILTIN_PREFIX "/builtin" 00028 00029 /*********************************************************************** 00030 * 00031 * MODEL STRUCTURE DECLARATIONS 00032 * 00033 ***********************************************************************/ 00034 00035 // a model for one region type 00036 typedef struct { 00037 char *name; // name for this class, e.g. quiet Sun 00038 int k; // number of gaussian components making the class 00039 double *params; // list of k, six-tuples of gaussian parameters 00040 } seg_onemodel_t; 00041 00042 // a model-set for an entire image-classification method 00043 // Note: The code currently assumes one component of the modelset 00044 // is for quiet sun, and 00045 // identifies it by the presence of "quiet" somewhere in the name. 00046 // The code also assumes one component is for active regions, and 00047 // identifies it by the presence of "active" somewhere in the name. 00048 // Case is significant. 00049 // So, it is best if some models[r].name contains "quiet" and another 00050 // contains "active". 00051 typedef struct { 00052 char *name; // identifying name for the whole model 00053 char *descrip; // readable description for the whole model 00054 char *version; // version identifier 00055 int nclass; // number of classes, e.g. 2 for quiet Sun vs. active region 00056 int ndim; // number of image observations (always ndim = 2 = M + Ic) 00057 char *format; // ordering of params (always = "var,diag-then-upper") 00058 double *alpha; // length-nclass vector of per-class probabilities 00059 seg_onemodel_t models[]; // length-nclass list of models, one for each class 00060 } seg_modelset_t; 00061 00062 /*********************************************************************** 00063 * 00064 * RUDIMENTARY MODEL API 00065 * 00066 ***********************************************************************/ 00067 00068 // parse json text into modelset object 00069 seg_modelset_t *seg_text2modelset(char *text, char **errmsg); 00070 // Read a file, return a modelset for that file 00071 seg_modelset_t *seg_modelfile2modelset(const char *filename, char **errmsg); 00072 // frees allocated seg_modelset_t (not a statically-allocated modelset!) 00073 void seg_modelset_destroy(seg_modelset_t *m); 00074 // get a modelset, built-in or external 00075 seg_modelset_t *seg_modelsetname2modelset(const char *name, char **errmsg, int enable_files); 00076 // return the i'th built-in modelset, or NULL 00077 seg_modelset_t *seg_modelset_builtin(int i); 00078 // get the number, within a modelset, of a certain class (e.g., quiet) 00079 int seg_modelname2modelnum(seg_modelset_t *modelset, char *modelname); 00080 // print out a modelset 00081 void seg_modelset_fprintf(FILE *fp, int verbose, seg_modelset_t *m); 00082 // print out all builtin modelsets 00083 void seg_modelsets_fprintf(FILE *fp, int verbose); 00084 00085 #endif // _hmi_segment_models_h_ 00086