/* Last edited on 2010-05-25 04:48:49 by stolfi */ pnm_image_t *rn_classif_pnm_image_from_dataset ( int NA, int NCL, rn_classif_labeler_t *lab, r2_t *ictr, double HV, int NXY, int NSUB, double sigma ); /* Produces an image with a pixel-size dot for each element of the dataset {D}. The dots are colored according to their {classD} values, in the same color scheme. Assumes {classD} ranges over {0..NCD}. Requires {NA == 2} and {D.NA >= 2}, and plots only the first 2 attributes of each sample against a white background. If {lab2} is not NULL, the brightness of the background is modified according to the class {cl2} assigned by {(NA,NCL,lab)}. If {cl2 = 0} it remains white, otherwise it is replced by darker shades of gray. The parameters {ictr,HV,NXY,NSUB,sigma} have the same meaning as for {rn_classif_pnm_image_from_labeler}, except that {sigma} and {NSUB} apply only to the background painting with {NA,NCL,lab}. The samples of {D} are not perturbed by the {sigma}-noise and their dots are anti-aliased in any case. */ pnm_image_t *rn_classif_pnm_image_from_dataset ( int NA, int NCD, rn_classif_dataset_t *D, int classD[], int NCL, rn_classif_labeler_t *lab, r2_t *ictr, double HV, int NXY, int NSUB, double sigma ) { demand(NA == 2, "problem is not two-dimensional"); demand(D->NA >= NA, "not enough attributes in dataset"); /* Assign colors to classes: */ frgb_t *cmap = rn_classif_pick_class_colors(NCD); float_image_t *fim = float_image_new(3, NXY, NXY); /* Paint a white background shadowed by {lab}: */ rn_classif_float_image_paint_labeler(fim, NA, 0, NULL, NCL, lab, ictr, HV, NSUB, sigma, cmap); /* Paint the dots over it: */ rn_classif_float_image_paint_dataset(fim, NA, NCD, D, classD, ictr, HV, 3, cmap); pnm_image_t *pim = float_image_to_pnm_image(fim, 3, NULL, NULL, NULL, 255, TRUE, FALSE); float_image_free(fim); free(cmap); return pim; } auto void debug_frgb(frgb_t val, char *spc); void debug_frgb(frgb_t val, char *spc) { if (spc == NULL) { fprintf(stderr, "\n"); } else { fprintf(stderr, " %s ( %6.4f %6.4f %6.4f )\n", spc, val.c[0], val.c[1], val.c[2]); } } /* bool_t debug = (r2_norm(pctr) <= 1.1) && (lab2 != NULL); */ bool_t debug = FALSE; if (debug) { debug_frgb(val, "RGB"); } if (debug) { debug_frgb(val, "HTY"); } if (debug) { debug_frgb(val, "HTY"); } if (debug) { debug_frgb(val, "RGB"); } if (debug) { debug_frgb(val, NULL); } typedef struct rn_classif_sample_t { int class; /* The nominal class of the sample, or 0 for `no clss'. */ float weight; /* A parameter for the distance function. */ double *attr; /* {attr[t]} is attribute {t} of the sample. */ } rn_classif_sample_t; /* A sample vector with a weight and a nominal classification. */