int main(int argc, char **argv) { if ((argc < 5) || !strcmp(argv[1], "--help")) { usage(); return (0); } if (!strcmp(argv[1], "--erode")) { s_ppm *ppm = load_ppm(argv[2]); filter(&ppm, atoi(argv[3]), argv[4], "erode"); } if (!strcmp(argv[1], "--dilate")) { s_ppm *ppm = load_ppm(argv[2]); filter(&ppm, atoi(argv[3]), argv[4], "dilate"); } if (!strcmp(argv[1], "--mh")) { s_ppm *input = load_ppm(argv[2]); s_ppm *ref = load_ppm(argv[3]); meta_heur(&input, &ref, argv[4], atoi(argv[5])); } return (0); }
/*! ** main this is the main fucntion of the progamm learn ** ** @param argc ** @param argv ** ** @return */ int main(int argc, char **argv) { s_ppm *input = NULL; if ((argc < 1) && !strcmp(argv[1], "--help")) { usage(); return (0); } if (argc < 4) { usage(); return (1); } if (!strcmp(argv[1], "--create")) { input = load_ppm(argv[2]); create(input, argv[3]); free_ppm(input); } if (!strcmp(argv[1], "--merge")) opt_merge(argv); if (!strcmp(argv[1], "--dir")) learn_dir(argv[2], argv[3]); return (0); }
Grid* load_grid_from_ppm(char *path, unsigned int max_width, unsigned int max_height) { unsigned int i, j; Image *img = load_ppm(path); Grid *grid; if (img == NULL) { print_error("Échec de chargement de la grille."); return NULL; } grid = new_grid(min(max_width, img->width), min(max_height, img->height)); for (i=0; i < grid->width; i++) for (j=0; j <grid->height; j++) { if (img->pixels[i][j].grey < 255) // le pixel n'est pas blanc grid->tiles[i][j] = '+'; else grid->tiles[i][j] = '.'; } delete_image(img); // On libère la mémoire return grid; }
int main(int c, char *v[]){ if (c != 3) { printf("Usage: %s input_image output_image\n", v[0]); } else { int w, h; int *x = load_ppm(v[1], &w, &h); fprintf(stderr, "Got a %dx%d image.\n", w, h); // some processing here... // Umbralizado. int th = 100; int i; for (i = 0; i < 3 * w * h; i++) { if (x[i] <= th) { x[i] = 0; } else { x[i] = 255; } } save_ppm(v[2], x, w, h); free(x); return 0; } }
int main(int argc,char **args) { const char *infilename="/dev/stdin"; int nblocks=4; int n_scale=3; int orientations_per_scale[50]={8,8,4}; while(*++args) { const char *a=*args; if(!strcmp(a,"-h")) usage(); else if(!strcmp(a,"-nblocks")) { if(!sscanf(*++args,"%d",&nblocks)) { fprintf(stderr,"could not parse %s argument",a); usage(); } } else if(!strcmp(a,"-orientationsPerScale")) { char *c; n_scale=0; for(c=strtok(*++args,",");c;c=strtok(NULL,",")) { if(!sscanf(c,"%d",&orientations_per_scale[n_scale++])) { fprintf(stderr,"could not parse %s argument",a); usage(); } } } else { infilename=a; } } color_image_t *im=load_ppm(infilename); float *desc = color_gist_scaletab(im,nblocks,n_scale,orientations_per_scale); int i; int descsize=0; /* compute descriptor size */ for(i=0;i<n_scale;i++) descsize+=nblocks*nblocks*orientations_per_scale[i]; descsize*=3; /* color */ /* print descriptor */ for(i=0;i<descsize;i++) printf("%.4f ",desc[i]); printf("\n"); free(desc); color_image_delete(im); return 0; }
int main(int argc, char** argv) { image_t img; image_new(&img); load_ppm("a.ppm", &img); image_median_filter(&img); save_ppm("b.ppm", &img); image_free(&img); return 0; }
void *load_image(const char *fname, unsigned long *xsz, unsigned long *ysz) { FILE *fp = fopen(fname, "r"); if(!fp) { fprintf(stderr, "failed to open: %s\n", fname); return 0; } if(check_ppm(fp)) { return load_ppm(fp, xsz, ysz); } fclose(fp); fprintf(stderr, "unsupported image format\n"); return 0; }
void * load_image(const char * fname, unsigned long * xsz, unsigned long * ysz) { // Load a ppm image FILE * fp; fp = fopen(fname, "r"); if (fp == NULL) { // Cannot open file fprintf(stderr, "failed to open: %s\n", fname); return 0; } if (check_ppm(fp)) { // Is it a P6 ppm? return load_ppm(fp, xsz, ysz); // Open the image } fclose(fp); fprintf(stderr, "unsupported image format\n"); // It is not a P6 ppm image return 0; }
static app_t * app_create (const app_params_t *params) { app_t *self = (app_t*) calloc (1, sizeof (app_t)); self->foo = params->foo; if (0 != load_ppm (self, params->filename)) goto fail; setup_gui (self); bot_gtk_gl_image_area_set_image_format (self->gl_area, self->img_width, self->img_height, GL_RGB); bot_gtk_gl_image_area_upload_image (self->gl_area, self->img, self->img_stride); return self; fail: app_destroy (self); return NULL; }
int main(int argc, char **argv) { FILE *f_out; unsigned char buffer[256]; int j; if (argc == 1) { fprintf(stderr, "Usage: %s <filename>\n", argv[0]); fprintf(stderr, " Where <filename> if the ppm file source.\n"); return(-1); } if ( load_ppm(argv[1]) < 0) { fprintf(stderr, "Error during source file load\n"); return(-1); } f_out = fopen("out.h", "w"); /* Write precompiler test to avoid multiple includes */ fprintf(f_out, "#ifndef IMG_H\n#define IMG_H\n"); fprintf(f_out, "unsigned char img[512] = {\n"); /* Compute line 0 (bottom) */ for (j = 0; j < 128; j++) { buffer[0] = 0; buffer[0] |= (raw_img[24][j] << 7); buffer[0] |= (raw_img[25][j] << 6); buffer[0] |= (raw_img[26][j] << 5); buffer[0] |= (raw_img[27][j] << 4); buffer[0] |= (raw_img[28][j] << 3); buffer[0] |= (raw_img[29][j] << 2); buffer[0] |= (raw_img[30][j] << 1); buffer[0] |= (raw_img[31][j] << 0); fprintf(f_out, "0x%.2x, ", buffer[0]); } fprintf(f_out, "\n"); /* Compute line 1 */ for (j = 0; j < 128; j++) { buffer[0] = 0; buffer[0] |= (raw_img[16][j] << 7); buffer[0] |= (raw_img[17][j] << 6); buffer[0] |= (raw_img[18][j] << 5); buffer[0] |= (raw_img[19][j] << 4); buffer[0] |= (raw_img[20][j] << 3); buffer[0] |= (raw_img[21][j] << 2); buffer[0] |= (raw_img[22][j] << 1); buffer[0] |= (raw_img[23][j] << 0); fprintf(f_out, "0x%.2x, ", buffer[0]); } fprintf(f_out, "\n"); /* Compute line 2 */ for (j = 0; j < 128; j++) { buffer[0] = 0; buffer[0] |= (raw_img[8][j] << 7); buffer[0] |= (raw_img[9][j] << 6); buffer[0] |= (raw_img[10][j] << 5); buffer[0] |= (raw_img[11][j] << 4); buffer[0] |= (raw_img[12][j] << 3); buffer[0] |= (raw_img[13][j] << 2); buffer[0] |= (raw_img[14][j] << 1); buffer[0] |= (raw_img[15][j] << 0); fprintf(f_out, "0x%.2x, ", buffer[0]); } fprintf(f_out, "\n"); /* Compute line 3 */ for (j = 0; j < 128; j++) { buffer[0] = 0; buffer[0] |= (raw_img[0][j] << 7); buffer[0] |= (raw_img[1][j] << 6); buffer[0] |= (raw_img[2][j] << 5); buffer[0] |= (raw_img[3][j] << 4); buffer[0] |= (raw_img[4][j] << 3); buffer[0] |= (raw_img[5][j] << 2); buffer[0] |= (raw_img[6][j] << 1); buffer[0] |= (raw_img[7][j] << 0); fprintf(f_out, "0x%.2x", buffer[0]); if (j != 127) fprintf(f_out, ", "); } fprintf(f_out, "\n"); /* Write the array end tag */ fprintf(f_out,"};\n"); fprintf(f_out,"#endif\n"); fclose(f_out); return(0); }