// main function int main_registration(int argc, char **argv) { // process input arguments if (argc != 4) { fprintf(stderr, "usage:\n\t%s left right Tright\n", *argv); // 0 1 2 3 return 1; } char *filename_left = argv[1]; char *filename_right = argv[2]; char *filename_Tright = argv[3]; // read input image int w, h; float *left = iio_read_image_float(filename_left, &w, &h); float *right = iio_read_image_float(filename_right, &w, &h); // allocate space for the output image float *out = malloc(w*h*sizeof(float)); // run the algorithm registration(out, left, right, w, h); // save the output image iio_write_image_float(filename_Tright, out, w, h); // cleanup and exit free(left); free(right); free(out); return 0; }
int main(int argc, char *argv[]) { if (argc != 5) { fprintf(stderr, "usage:\n\t" "%s boundary.png data.png mask.png out.png\n", *argv); // 0 1 2 3 4 return 1; } char *filename_inpu = argv[1]; char *filename_data = argv[2]; char *filename_mask = argv[3]; char *filename_out = argv[4]; int w[3], h[3]; float *inpu = iio_read_image_float(filename_inpu, w, h); float *data = iio_read_image_float(filename_data, w+1, h+1); float *mask = iio_read_image_float(filename_mask, w+2, h+2); if (w[0] != w[1] || h[0] != h[1] || w[0] != w[2] || h[0] != h[2]) return fprintf(stderr, "input image files sizes mismatch"); float *out = xmalloc(*w**h*sizeof*out); for (int i = 0; i < *w * *h; i++) if (mask[i] > 0) inpu[i] = NAN; int nscales = NSCALES(); poisson_recursive(out, inpu, data, *w, *h, nscales); iio_write_image_float(filename_out, out, *w, *h); return 0; }
int main_compute(int c, char *v[]) { // input arguments bool do_only_warp = pick_option(&c, &v, "w", NULL); if (do_only_warp) return main_warp(c, v); bool do_center = pick_option(&c, &v, "c", NULL); if (c != 7) { fprintf(stderr, "usage:\n\t" "%s a.png b.png Pa.txt Pb.txt in.tiff out.tiff\n", *v); // 0 1 2 3 4 5 6 return 1; } char *filename_a = v[1]; char *filename_b = v[2]; char *matrix_pa = v[3]; char *matrix_pb = v[4]; char *filename_in = v[5]; char *filename_out = v[6]; // read input images and matrices int wa, wb, wi, ha, hb, hi; float *a = iio_read_image_float(filename_a, &wa, &ha); float *b = iio_read_image_float(filename_b, &wb, &hb); float *h0 = iio_read_image_float(filename_in, &wi, &hi); double PA[8], PB[8]; read_n_doubles_from_string(PA, matrix_pa, 8); read_n_doubles_from_string(PB, matrix_pb, 8); // perform centering, if necessary if (do_center) { center_projection(PA, wa/2, ha/2); center_projection(PB, wb/2, hb/2); } // allocate space for output image float *out = xmalloc(wi * hi * sizeof*out); // run the algorithm float alpha2 = ALPHA()*ALPHA(); int niter = NITER(); int nwarps = NWARPS(); int nscales = NSCALES(); mnehs_affine_ms(out, h0, wi, hi, a, wa, ha, b, wb, hb, PA, PB, alpha2, niter, nscales); //for (int i = 0; i < nwarps; i++) //{ // mnehs_affine(out, h0, wi,hi, a,wa,ha, b,wb,hb, PA, PB, alpha2, niter); // memcpy(h0, out, wi * hi * sizeof*h0); //} // save the output image iio_save_image_float(filename_out, out, wi, hi); // cleanup and exit free(out); free(h0); free(a); free(b); return 0; }
int main(int argc, char *argv[]) { if (argc != 5) { fprintf(stderr, "usage:\n\t" "%s metric colors outk outi\n", *argv); //0 1 2 3 4 return 1; } char *filename_metric = argv[1]; char *filename_colors = argv[2]; char *filename_outhue = argv[3]; char *filename_outint = argv[4]; int w[2], h[2], pd; float *metric = iio_read_image_float(filename_metric, w, h); float *colors = iio_read_image_float_vec(filename_colors, w+1, h+1,&pd); if (w[0] != w[1] || h[0] != h[1]) return fprintf(stderr, "input image files sizes mismatch"); float *outhue = xmalloc(pd**w**h*sizeof*outhue); float *outint = xmalloc(pd**w**h*sizeof*outhue); lapbe_colorizer(outhue, outint, metric, colors, *w, *h, pd); iio_save_image_float_vec(filename_outhue, outhue, *w, *h, pd); iio_save_image_float_vec(filename_outint, outint, *w, *h, pd); free(outhue); free(outint); free(metric); free(colors); return 0; }
int main(int c, char *v[]) { if (c != 6) { fprintf(stderr, "usage:\n\t%s width i0 m0 i1 m1\n", *v); // 0 1 2 3 4 5 return EXIT_FAILURE; } int width = atoi(v[1]); char *in_image = v[2]; char *in_mask = v[3]; char *out_image = v[4]; char *out_mask = v[5]; int w, h, pd, ww, hh; float *x = iio_read_image_float_vec(in_image, &w, &h, &pd); float *m = iio_read_image_float(in_mask, &ww, &hh); if (w != ww || h != hh) fail("size mismatch"); fillcorners(x, m, w, h, pd, width); iio_save_image_float_vec(out_image, x, w, h, pd); iio_save_image_float(out_mask, m, w, h); free(x); free(m); return EXIT_SUCCESS; }
// main function int main(int argc, char **argv) { // process input arguments if (argc != 5) { fprintf(stderr, "usage:\n\t%s dx dy in out\n", *argv); // 0 1 2 3 4 return 1; } int dx = atoi(argv[1]); int dy = atoi(argv[2]); char *filename_in = argv[3]; char *filename_out = argv[4]; // read input image int w, h; float *in = iio_read_image_float(filename_in, &w, &h); // allocate space for output image float *out = malloc(w*h*sizeof(float)); // run the algorithm apply_translation(out, dx, dy, in, w, h); // save output image iio_save_image_float(filename_out, out, w, h); // cleanup and exit free(in); free(out); return 0; }
int main_rpc_warpabt(int c, char *v[]) { TIFFSetWarningHandler(NULL);//suppress warnings // input arguments if (c != 9) { fprintf(stderr, "usage:\n\t" "%s a.{tiff,rpc} b.{tiff,rpc} ax ay in.tif out.tif\n", *v); //0 1 2 3 4 5 6 7 8 return 1; } char *filename_a = v[1]; char *filename_rpca = v[2]; char *filename_b = v[3]; char *filename_rpcb = v[4]; double axyh[3] ={atof(v[5]), atof(v[6]), 0}; char *filename_h0 = v[7]; char *filename_out = v[8]; // read input images int megabytes = 800; struct tiff_tile_cache ta[1], tb[1]; tiff_tile_cache_init(ta, filename_a, megabytes); tiff_tile_cache_init(tb, filename_b, megabytes); int pd = ta->i->spp; if (pd != tb->i->spp) fail("image color depth mismatch\n"); // read input rpcs struct rpc rpca[1]; struct rpc rpcb[1]; read_rpc_file_xml(rpca, filename_rpca); read_rpc_file_xml(rpcb, filename_rpcb); // read initialized raster int w, h; float *in_h0 = iio_read_image_float(filename_h0, &w, &h); // allocate space for output raster float *out_h = xmalloc(w * h * sizeof*out_h); // run the algorithm float alpha2 = ALPHA()*ALPHA(); int niter = NITER(); int nwarps = NWARPS(); for (int i = 0; i < nwarps; i++) { mnehs_rpc(out_h, in_h0, w,h,ta,rpca,tb,rpcb,axyh, alpha2,niter); memcpy(in_h0, out_h, w*h*sizeof*in_h0); } // save the output raster iio_save_image_float(filename_out, out_h, w, h); // cleanup and exit free(in_h0); free(out_h); tiff_tile_cache_free(ta); tiff_tile_cache_free(tb); return 0; }
int main(int c, char *v[]) { if (c != 5) { fprintf(stderr, "usage:\n\t%s img step nscales outpat\n", *v); // 0 1 2 3 4 return EXIT_FAILURE; } char *filename_in = v[1]; float scalestep = atof(v[2]); int nscales = atoi(v[3]); char *filepattern_out = v[4]; int w, h; float *x = iio_read_image_float(filename_in, &w, &h); float *pyrx[nscales]; int pyrw[nscales], pyrh[nscales]; produce_upwards_pyramid(pyrx, pyrw, pyrh, x, w, h, nscales, scalestep); for (int i = 0; i < nscales; i++) { char buf[0x100]; snprintf(buf, 0x100, filepattern_out, i); printf("SCALE NUMBER %d: %dx%d (%d) => \"%s\"\n", i, pyrw[i], pyrh[i], buf); iio_save_image_float(buf, pyrx[i], pyrw[i], pyrh[i]); } return EXIT_SUCCESS; }
// main function int main(int argc, char **argv) { // process input arguments if (argc != 5) { fprintf(stderr, "usage:\n\t%s in out1 out2 out3\n", *argv); // 0 1 2 3 4 return 1; } char *filename_in = argv[1]; char *filename_out1 = argv[2]; char *filename_out2 = argv[3]; char *filename_out3 = argv[4]; // read input image int w, h; float *in = iio_read_image_float(filename_in, &w, &h); // allocate space for the output images float *out1 = malloc(w*h*sizeof(float)); float *out2 = malloc(w*h*sizeof(float)); float *out3 = malloc(w*h*sizeof(float)); // run the algorithm fill_three_parts(out1, out2, out3, in, w, h); // save the output images iio_save_image_float(filename_out1, out1, w, h/3); iio_save_image_float(filename_out2, out2, w, h/3); iio_save_image_float(filename_out3, out3, w, h/3); // cleanup and exit free(out1); free(out2); free(out3); free(in); return 0; }
int main(int argc, char *argv[]) { // process input arguments if (argc != 6) { fprintf(stderr, "usage:\n \t imageIn n i j imageOut \n"); // 0 1 2 3 4 5 } char *filename_ImgIn1 = argv[1]; int n = atof(argv[2]); int i = atof(argv[3]); int j = atof(argv[4]); char *filename_ImgOut = argv[5]; //read input images int w, h; float *im = iio_read_image_float(filename_ImgIn1, &w, &h); //allocate space for output image float *out = malloc(n*n*sizeof(float)); echantillon_size_n(im, w, n, i, j, out); //save image iio_save_image_float(filename_ImgOut, out, n, n); //cleanup and exit free(out); return 0; }
int main(int argc, char *argv[]) { if (argc != 9) { fprintf(stderr, "usage:\n\t" "%s a b alpha niter eps step nscales f\n", *argv); // 0 1 2 3 4 5 6 7 8 return EXIT_FAILURE; } char *filename_a = argv[1]; char *filename_b = argv[2]; float alpha = atof(argv[3]); int niter = atoi(argv[4]); float epsilon = atof(argv[5]); float scalestep = atof(argv[6]); int nscales = atoi(argv[7]); char *filename_f = argv[8]; int w, h, ww, hh; float *a = iio_read_image_float(filename_a, &w, &h); float *b = iio_read_image_float(filename_b, &ww, &hh); if (w != ww || h != hh) fail("input image size mismatch"); float *u = xmalloc(w * h * sizeof(float)); float *v = xmalloc(w * h * sizeof(float)); float Nscales = 1.5+log(BAD_MIN(w,h)/3.0)/log(fabs(scalestep)); if (Nscales < nscales) nscales = Nscales; float fdata[3] = {alpha, niter, epsilon}; generic_multi_scale_optical_flow(u, v, a, b, w, h, genericized_lk, fdata, nscales, scalestep, 0); float *f = xmalloc(w*h*2*sizeof*f); for (int i = 0; i < w*h; i++) { f[2*i] = u[i]; f[2*i+1] = v[i]; } iio_save_image_float_vec(filename_f, f, w, h, 2); xfree(f); xfree(u); xfree(v); xfree(a); xfree(b); return EXIT_SUCCESS; }
int main_rpc_warpabt(int c, char *v[]) { TIFFSetWarningHandler(NULL);//suppress warnings // input arguments if (c != 10) { fprintf(stderr, "usage:\n\t" "%s a.{tiff,rpc} b.{tiff,rpc} ax ay h0.tif o{a,b}.tiff\n", *v); //0 1 2 3 4 5 6 7 8 9 return 1; } char *filename_a = v[1]; char *filename_rpca = v[2]; char *filename_b = v[3]; char *filename_rpcb = v[4]; double axyh[3] ={atof(v[5]), atof(v[6]), 0}; char *filename_h0 = v[7]; char *filename_outa = v[8]; char *filename_outb = v[9]; // read input images and rpcs //int wa, wb, ha, hb, pd, pdb; //float *a = iio_read_image_float_vec(filename_a, &wa, &ha, &pd); //float *b = iio_read_image_float_vec(filename_b, &wb, &hb, &pdb); int megabytes = 800; struct tiff_tile_cache ta[1], tb[1]; tiff_tile_cache_init(ta, filename_a, megabytes); tiff_tile_cache_init(tb, filename_b, megabytes); int pd = ta->i->spp; if (pd != tb->i->spp) fail("image color depth mismatch\n"); struct rpc rpca[1]; struct rpc rpcb[1]; read_rpc_file_xml(rpca, filename_rpca); read_rpc_file_xml(rpcb, filename_rpcb); int w, h; float *h0 = iio_read_image_float(filename_h0, &w, &h); // allocate space for output images float *outa = xmalloc(w * h * pd * sizeof*outa); float *outb = xmalloc(w * h * pd * sizeof*outb); // run the algorithm rpc_warpabt(outa, outb, h0, w,h,pd, ta,rpca, tb,rpcb, axyh); // save the output images iio_save_image_float_vec(filename_outa, outa, w, h, pd); iio_save_image_float_vec(filename_outb, outb, w, h, pd); // cleanup and exit free(outa); free(outb); tiff_tile_cache_free(ta); tiff_tile_cache_free(tb); return 0; }
int main(int c, char *v[]) { int gpar = atoi(pick_option(&c, &v, "g", "1")); if (c < 4) { fprintf(stderr, "usage:\n\t%s {sum|min|max|avg|mul|med] [v1 ...] > out\n", *v); // 0 1 2 3 return EXIT_FAILURE; } int n = c - 2; char *operation_name = v[1]; float (*f)(float *,int) = NULL; if (0 == strcmp(operation_name, "sum")) f = float_sum; if (0 == strcmp(operation_name, "mul")) f = float_mul; if (0 == strcmp(operation_name, "prod")) f = float_mul; if (0 == strcmp(operation_name, "avg")) f = float_avg; if (0 == strcmp(operation_name, "min")) f = float_min; if (0 == strcmp(operation_name, "max")) f = float_max; if (0 == strcmp(operation_name, "med")) f = float_med; if (0 == strcmp(operation_name, "mod")) f = float_mod; if (0 == strcmp(operation_name, "cnt")) f = float_cnt; if (0 == strcmp(operation_name, "medi")) f = float_med; if (0 == strcmp(operation_name, "medv")) f = float_medv; if (0 == strcmp(operation_name, "rnd")) f = float_pick; if (0 == strcmp(operation_name, "first")) f = float_first; if (*operation_name == 'q') { float p = atof(1 + operation_name); f = float_percentile; f(&p, -1); } if (!f) fail("unrecognized operation \"%s\"", operation_name); bool (*isgood)(float) = NULL; if (0 == gpar) isgood = isgood_finite; if (1 == gpar) isgood = isgood_numeric; if (2 == gpar) isgood = isgood_always; if (!isgood) fail("unrecognized goodness %d", gpar); float *x[n]; int w[n], h[n]; for (int i = 0; i < n; i++) x[i] = iio_read_image_float(v[i+2], w + i, h + i); for (int i = 0; i < n; i++) { if (w[i] != *w || h[i] != *h) fail("%dth image size mismatch\n", i); } float (*y) = xmalloc(*w * *h * sizeof*y); for (int i = 0; i < *w * *h; i++) { float tmp[n]; int ngood = 0; for (int j = 0; j < n; j++) if (isgood(x[j][i])) tmp[ngood++] = x[j][i]; y[i] = f(tmp, ngood); } iio_save_image_float("-", y, *w, *h); return EXIT_SUCCESS; }
int main(int argc, char **argv) { //process input arguments if (argc != 4) { fprintf(stderr, "usage:\n \t imageIn n tile \n"); // 0 1 2 3 return 0; } char *filename_ImgIn = argv[1]; int n = atoi(argv[2]); char *fileout = argv[3]; char filename_tile[n*n][256]; for(int i = 0 ; i < n*n ; i++) { sprintf(filename_tile[i], "%s_%d.png", fileout, i+1); } //read input images int w, h; float *im = iio_read_image_float(filename_ImgIn, &w, &h); int w1 = floor(w/n); int h1 = floor(h/n); //allocate space for subimages float *tiles[n*n]; for(int i = 0 ; i < n*n ; i++) { tiles[i] = malloc(w1*h1*sizeof(float)); } //create tiles and rebuild image cut_n_parts(im, w, h, n, tiles); //save outputs for (int i = 0 ; i < n*n ; i++) { iio_save_image_float(filename_tile[i], tiles[i], w1, h1); } //cleanup and exit for(int i = 0 ; i < n*n ; i++) { free(tiles[i]); } return 0; }
int main(int argc, char *argv[]) { if (argc != 9 && argc != 8) { fprintf(stderr, "usage:\n\t" "%s a b method \"params\" step nscales lastscale [f]\n", *argv); // 0 1 2 3 4 5 6 7 8 return EXIT_FAILURE; } char *filename_a = argv[1]; char *filename_b = argv[2]; char *method_id = argv[3]; char *parstring = argv[4]; float scale_step = atof(argv[5]); int nscales = atoi(argv[6]); int last_scale = atoi(argv[7]); char *filename_f = argc > 8 ? argv[8] : "-"; float params[0x100]; int nparams = parse_floats(params, 0x100, parstring); int w, h, ww, hh; float *a = iio_read_image_float(filename_a, &w, &h); float *b = iio_read_image_float(filename_b, &ww, &hh); if (w != ww || h != hh) fail("input image size mismatch"); float *u = xmalloc(2 * w * h * sizeof(float)); float *v = u + w * h; // bound the number of scales to disallow images smaller than 16 pixels float Nscales = 1.5+log(BAD_MIN(w,h)/3.0)/log(fabs(scale_step)); if (Nscales < nscales) nscales = Nscales; multi_scale_optical_flow(method_id, params, nparams, u, v, a, b, w, h, nscales, scale_step, last_scale); iio_save_image_float_split(filename_f, u, w, h, 2); xfree(u); xfree(a); xfree(b); return EXIT_SUCCESS; }
// main function for testing the Horn-Schunck method from the command line int main(int argc, char *argv[]) { if ( (argc != 6) && (argc != 7) ) { return fprintf(stderr, "usage:\n\t%s niter alpha a b f\n", *argv); } // 0 1 2 3 4 5 int niter = atoi(argv[1]); double alpha = atof(argv[2]); const char *filename_a = argv[3]; const char *filename_b = argv[4]; const char *filename_f = argv[5]; int w, h, ww, hh; #ifdef OFPIX_DOUBLE ofpix_t *a = iio_read_image_double(filename_a, &w, &h); ofpix_t *b = iio_read_image_double(filename_b, &ww, &hh); #else ofpix_t *a = iio_read_image_float(filename_a, &w, &h); ofpix_t *b = iio_read_image_float(filename_b, &ww, &hh); #endif if ( (w != ww) || (h != hh) ) { return fprintf(stderr, "input images size mismatch\n"); } ofpix_t *u = new ofpix_t [2 * w * h]; ofpix_t *v = u + w * h; hs(u, v, a, b, w, h, niter, alpha); //save the flow float *f = new float[w * h * 2]; for (int i = 0; i < w * h; i++) { f[2 * i] = u[i]; f[2 * i + 1] = v[i]; } iio_save_image_float_vec( filename_f, f, w, h, 2 ); delete []f; delete [] u; return EXIT_SUCCESS; }
// main function int main(int argc, char **argv) { // process input arguments if (argc != 5) { fprintf(stderr, "usage:\n\t%s red green blue out\n", *argv); // 0 1 2 3 4 return 1; } char *filename_r = argv[1]; char *filename_g = argv[2]; char *filename_b = argv[3]; char *filename_rgb = argv[4]; // read input images int w[3], h[3]; float *r = iio_read_image_float(filename_r, w+0, h+0); float *g = iio_read_image_float(filename_g, w+1, h+1); float *b = iio_read_image_float(filename_b, w+2, h+2); // check that the input images have the same size if (w[1]!=w[0] || w[2]!=w[0] || h[1]!=h[0] || h[2]!=h[0]) { fprintf(stderr, "input sizes mismatch(%d,%d)(%d,%d)(%d,%d)\n", w[0],h[0], w[1],h[1], w[2],h[2] ); return 1; } // allocate space for the output image float *rgb = malloc(3*w[0]*h[0]*sizeof(float)); // run the algorithm join_rgb(rgb, r, g, b, w[0], h[0]); // save the output image iio_save_image_float_vec(filename_rgb, rgb, w[0], h[0], 3); // cleanup and exit free(r); free(g); free(b); free(rgb); return 0; }
int main (int argc, char **argv) { /* ppatameter parsing - parameters*/ if(argc<5) { fprintf (stderr, "too few parameters\n"); fprintf (stderr, "apply a 'morphologic' operation over the square structuring element of size sz\n"); fprintf (stderr, " usage: %s input {min,max,median,average,random,rank} sz out [ struc_elem ]\n",argv[0]); return 1; } // input int nc,nr,nch; float *in = iio_read_image_float_split(argv[1], &nc, &nr, &nch); // operation char *operation = argv[2]; // construct structuring element int se_nr, se_nc; se_nr = se_nc = atoi(argv[3]); float sse[se_nr*se_nc]; // static memory float *se = sse; int i; for (i=0;i<se_nr*se_nc;i++) se[i] = 1; int ctr_c = se_nc /2; // the center int ctr_r = se_nr /2; // if a structuring element is passed use it insted of the one constructed if (argc >5) { se = iio_read_image_float(argv[5], &se_nc, &se_nr); ctr_c = se_nc /2; // the center ctr_r = se_nr /2; } // allocate output float *out = malloc(nc*nr*nch*sizeof*out); // call the algorithm for (int i=0;i<nch;i++) morphoop(in + nc*nr*i,nc,nr, se, se_nc, se_nr, ctr_c, ctr_r, operation, out + nc*nr*i); iio_save_image_float_split(argv[4], out, nc, nr, nch); free(in); free(out); return 0; }
int main_warp(int c, char *v[]) { // input arguments bool do_center = pick_option(&c, &v, "c", NULL); if (c != 7) { fprintf(stderr, "usage:\n\t" "%s a.png b.png Pa.txt Pb.txt in.tiff amb.png\n", *v); // 0 1 2 3 4 5 6 return 1; } char *filename_a = v[1]; char *filename_b = v[2]; char *matrix_pa = v[3]; char *matrix_pb = v[4]; char *filename_in = v[5]; char *filename_out = v[6]; // read input images and matrices int wa, wb, wi, ha, hb, hi, pd, pdb; float *a = iio_read_image_float_vec(filename_a, &wa, &ha, &pd); float *b = iio_read_image_float_vec(filename_b, &wb, &hb, &pdb); float *h0 = iio_read_image_float(filename_in, &wi, &hi); double PA[8], PB[8]; read_n_doubles_from_string(PA, matrix_pa, 8); read_n_doubles_from_string(PB, matrix_pb, 8); if (pd != pdb) fail("input pair has different color depth"); // perform centering, if necessary if (do_center) { fprintf(stderr, "centering projection matrices\n"); center_projection(PA, wa/2, ha/2); center_projection(PB, wb/2, hb/2); } // allocate space for output image float *out = xmalloc(wi * hi * pd * sizeof*out); // run the algorithm mnehs_affine_warp(out, h0, wi,hi,pd, a,wa,ha, b,wb,hb, PA, PB); // save the output image iio_save_image_float_vec(filename_out, out, wi, hi, pd); // cleanup and exit free(out); free(h0); free(a); free(b); return 0; }
int main(int c, char *v[]) { if (c != 1 && c != 2) { fprintf(stderr, "usage:\n\t%s [img]\n", *v); // 0 1 return 1; } char *in_img = c > 1 ? v[1] : "-"; int w, h; float *x = iio_read_image_float(in_img, &w, &h); float s = spread(x, w, h); printf("%.25lf\n", s); free(x); return 0; }
int main(int c, char *v[]) { if (c != 3) { fprintf(stderr, "usage:\n\t%s colors heights > ply\n", *v); // 0 1 2 return 1; } char *filename_colors = v[1]; char *filename_heights = v[2]; int w, h, pd, ww, hh; float *colors = iio_read_image_float_vec(filename_colors, &w, &h, &pd); float *heights = iio_read_image_float(filename_heights, &ww, &hh); if (w != ww || h != hh) fail("color and height image size mismatch"); if (pd != 3) fail("expecting a color image"); printf("ply\n"); printf("format ascii 1.0\n"); printf("comment created by cutrecombine\n"); printf("element vertex %d\n", w*h); printf("property float x\n"); printf("property float y\n"); printf("property float z\n"); printf("property uchar red\n"); printf("property uchar green\n"); printf("property uchar blue\n"); printf("element face %d\n", (w-1)*(h-1)); printf("property list uchar int vertex_index\n"); printf("end_header\n"); float (*color)[w][pd] = (void*)colors; float (*height)[w] = (void*)heights; for (int j = 0; j < h; j++) for (int i = 0; i < w; i++) printf("%d %d %g %g %g %g\n", i, -j, height[j][i], color[j][i][0], color[j][i][1], color[j][i][2]); for (int j = 0; j < h-1; j++) for (int i = 0; i < w-1; i++) { int q[4] = {j*w+i, (j+1)*w+i, (j+1)*w+i+1, j*w+i+1}; printf("4 %d %d %d %d\n", q[0], q[1], q[2], q[3]); } return 0; }
int main(int c, char *v[]) { if (c < 4) { fprintf(stderr, "usage:\n\t%s {sum|min|max|avg|mul|med] [v1 ...] > out\n", *v); // 0 1 2 3 return EXIT_FAILURE; } int n = c - 2; char *operation_name = v[1]; float (*f)(float *,int) = NULL; if (0 == strcmp(operation_name, "sum")) f = float_sum; if (0 == strcmp(operation_name, "mul")) f = float_mul; if (0 == strcmp(operation_name, "prod")) f = float_mul; if (0 == strcmp(operation_name, "avg")) f = float_avg; if (0 == strcmp(operation_name, "min")) f = float_min; if (0 == strcmp(operation_name, "max")) f = float_max; if (0 == strcmp(operation_name, "med")) f = float_med; if (0 == strcmp(operation_name, "mod")) f = float_mod; if (0 == strcmp(operation_name, "medi")) f = float_med; if (0 == strcmp(operation_name, "medv")) f = float_medv; if (0 == strcmp(operation_name, "rnd")) f = float_pick; if (0 == strcmp(operation_name, "first")) f = float_first; if (!f) fail("unrecognized operation \"%s\"", operation_name); float *x[n]; int w[n], h[n]; for (int i = 0; i < n; i++) x[i] = iio_read_image_float(v[i+2], w + i, h + i); for (int i = 0; i < n; i++) { if (w[i] != *w || h[i] != *h) fail("%dth image size mismatch\n", i); } float (*y) = xmalloc(*w * *h * sizeof*y); for (int i = 0; i < *w * *h; i++) { float tmp[n]; int ngood = 0; for (int j = 0; j < n; j++) if (isgood(x[j][i])) tmp[ngood++] = x[j][i]; y[i] = f(tmp, ngood); } iio_save_image_float("-", y, *w, *h); return EXIT_SUCCESS; }
int main(int c, char *v[]) { if (c != 2 && c != 1 && c != 3) { fprintf(stderr, "usage:\n\t%s [in [out]]\n", *v); // 0 1 2 return 1; } char *filename_in = c > 1 ? v[1] : "-"; char *filename_out = c > 2 ? v[2] : "-"; int w, h; float *x = iio_read_image_float(filename_in, &w, &h); long double H[256]; fill_histogram(H, x, w*h); accumulate_histogram(H); equalize_inplace(x, H, w*h); iio_write_image_float(filename_out, x, w, h); return 0; }
int main(int c, char *v[]) { if (c != 2 && c != 3 && c != 4) { fprintf(stderr, "usage:\n\t%s variances [in [out]]\n", *v); // 0 1 2 3 return 1; } char *filename_sigma = v[1]; char *filename_in = c > 2 ? v[2] : "-"; char *filename_out = c > 3 ? v[3] : "-"; int w, h, ww, hh, pd; float *sigma = iio_read_image_float(filename_sigma, &w, &h); float *x = iio_read_image_float_split(filename_in, &ww, &hh, &pd); if (w != ww || h != hh) fail("variances and image size mismatch"); float *y = xmalloc(w*h*pd*sizeof*y); local_gaussian_blur(y, sigma, x, w, h, pd); iio_save_image_float_split(filename_out, y, w, h, pd); free(x); free(y); free(sigma); return 0; }
int main(int c, char *v[]) { if (c != 2 && c != 3) { fprintf(stderr, "usage:\n\t%s angle [img] >plot\n", *v); // 0 1 2 return 1; } float angle = atof(v[1]); char *in_img = c>2 ? v[2] : "-"; int w, h; float *x = iio_read_image_float(in_img, &w, &h); int n = NFAC()*(2+hypot(w+2,h+2)); fprintf(stderr, "geometry = %dx%d\n", w, h); fprintf(stderr, "n = %d\n", n); float l[n], musigma[2] = {0}; if (isfinite(angle)) cline(musigma, l, n, x, w, h, angle); else clineh(NULL, l, n, x, w, h); //plot_cline(l, n, v[1], musigma[0], musigma[1]); plot_cline2(l, n); free(x); return 0; }
int main(int c, char *v[]) { if (c < 6 || c > 48) { help(v[0]); return 1; } // utm zone and hemisphere: true for 'N' and false for 'S' int zone; bool hem; const char *utm_string = pick_option(&c, &v, "-utm-zone", "no_utm_zone"); parse_utm_string(&zone, &hem, utm_string); // ascii flag bool ascii = pick_option(&c, &v, "-ascii", NULL); // longitude-latitude bounding box double lon_m = atof(pick_option(&c, &v, "-lon-m", "-inf")); double lon_M = atof(pick_option(&c, &v, "-lon-M", "inf")); double lat_m = atof(pick_option(&c, &v, "-lat-m", "-inf")); double lat_M = atof(pick_option(&c, &v, "-lat-M", "inf")); // x-y bounding box double col_m = atof(pick_option(&c, &v, "-col-m", "-inf")); double col_M = atof(pick_option(&c, &v, "-col-M", "inf")); double row_m = atof(pick_option(&c, &v, "-row-m", "-inf")); double row_M = atof(pick_option(&c, &v, "-row-M", "inf")); // mask on the unrectified image grid const char *msk_orig_fname = pick_option(&c, &v, "-mask-orig", ""); int msk_orig_w, msk_orig_h; float *msk_orig = iio_read_image_float(msk_orig_fname, &msk_orig_w, &msk_orig_h); // rectifying homography double href_inv[9], hsec_inv[9]; int n_hom; const char *hom_string_ref = pick_option(&c, &v, "href", ""); if (*hom_string_ref) { double *hom = alloc_parse_doubles(9, hom_string_ref, &n_hom); if (n_hom != 9) fail("can not read 3x3 matrix from \"%s\"", hom_string_ref); invert_homography(href_inv, hom); } const char *hom_string_sec = pick_option(&c, &v, "hsec", ""); if (*hom_string_sec) { double *hom = alloc_parse_doubles(9, hom_string_sec, &n_hom); if (n_hom != 9) fail("can not read 3x3 matrix from \"%s\"", hom_string_sec); invert_homography(hsec_inv, hom); } // open disp and mask input images int w, h, nch, ww, hh, pd; float *dispy; float *dispx = iio_read_image_float_split(v[2], &w, &h, &nch); if (nch > 1) dispy = dispx + w*h; else dispy = calloc(w*h, sizeof(*dispy)); float *mask = iio_read_image_float(v[3], &ww, &hh); if (w != ww || h != hh) fail("disp and mask image size mismatch\n"); // open color images if provided uint8_t *clr = NULL; if (c > 6) { clr = iio_read_image_uint8_vec(v[6], &ww, &hh, &pd); if (w != ww || h != hh) fail("disp and color image size mismatch\n"); } // read input rpc models struct rpc rpc_ref[1], rpc_sec[1]; read_rpc_file_xml(rpc_ref, v[4]); read_rpc_file_xml(rpc_sec, v[5]); // outputs double p[2], q[2], X[3]; // count number of valid pixels, and determine utm zone int npoints = 0; for (int row=0; row<h; row++) for (int col=0; col<w; col++) { int pix = row*w + col; if (!mask[pix]) continue; // compute coordinates of pix in the full reference image double a[2] = {col, row}; apply_homography(p, href_inv, a); // check that it lies in the image domain bounding box if (round(p[0]) < col_m || round(p[0]) > col_M || round(p[1]) < row_m || round(p[1]) > row_M) continue; // check that it passes the image domain mask int x = (int) round(p[0]) - col_m; int y = (int) round(p[1]) - row_m; if ((x < msk_orig_w) && (y < msk_orig_h)) if (!msk_orig[y * msk_orig_w + x]) continue; // compute (lon, lat, alt) of the 3D point float dx = dispx[pix]; float dy = dispy[pix]; double b[2] = {col + dx, row + dy}; apply_homography(q, hsec_inv, b); intersect_rays(X, p, q, rpc_ref, rpc_sec); // check with lon/lat bounding box if (X[0] < lon_m || X[0] > lon_M || X[1] < lat_m || X[1] > lat_M) continue; // if it passed all these tests then it's a valid point npoints++; // if not defined, utm zone is that of the first point if (zone < 0) utm_zone(&zone, &hem, X[1], X[0]); } // print header for ply file FILE *ply_file = fopen(v[1], "w"); write_ply_header(ply_file, ascii, npoints, zone, hem, (bool) clr, false); // loop over all the pixels of the input disp map // a 3D point is produced for each non-masked disparity for (int row=0; row<h; row++) for (int col=0; col<w; col++) { int pix = row*w + col; if (!mask[pix]) continue; // compute coordinates of pix in the full reference image double a[2] = {col, row}; apply_homography(p, href_inv, a); // check that it lies in the image domain bounding box if (round(p[0]) < col_m || round(p[0]) > col_M || round(p[1]) < row_m || round(p[1]) > row_M) continue; // check that it passes the image domain mask int x = (int) round(p[0]) - col_m; int y = (int) round(p[1]) - row_m; if ((x < msk_orig_w) && (y < msk_orig_h)) if (!msk_orig[y * msk_orig_w + x]) continue; // compute (lon, lat, alt) of the 3D point float dx = dispx[pix]; float dy = dispy[pix]; double b[2] = {col + dx, row + dy}; apply_homography(q, hsec_inv, b); intersect_rays(X, p, q, rpc_ref, rpc_sec); // check with lon/lat bounding box if (X[0] < lon_m || X[0] > lon_M || X[1] < lat_m || X[1] > lat_M) continue; // convert (lon, lat, alt) to utm utm_alt_zone(X, X[1], X[0], zone); // colorization: if greyscale, copy the grey level on each channel uint8_t rgb[3]; if (clr) { for (int k = 0; k < pd; k++) rgb[k] = clr[k + pd*pix]; for (int k = pd; k < 3; k++) rgb[k] = rgb[k-1]; } // write to ply if (ascii) { fprintf(ply_file, "%0.17g %0.17g %0.17g ", X[0], X[1], X[2]); if (clr) fprintf(ply_file, "%d %d %d", rgb[0], rgb[1], rgb[2]); fprintf(ply_file, "\n"); } else { double XX[3] = {X[0], X[1], X[2]}; fwrite(XX, sizeof(double), 3, ply_file); if (clr) { unsigned char C[3] = {rgb[0], rgb[1], rgb[2]}; fwrite(rgb, sizeof(unsigned char), 3, ply_file); } } } fclose(ply_file); return 0; }
// main function int main(int argc, char **argv) { // process input arguments if (argc != 6) { fprintf(stderr, "usage:\n\t%s image der1 der2 der3 der4\n", *argv); // 0 1 2 3 4 5 return 1; } char *filename_image = argv[1]; char *filename_der1 = argv[2]; char *filename_der2 = argv[3]; char *filename_der3 = argv[4]; char *filename_der4 = argv[5]; // read input image int w, h; float *im = iio_read_image_float(filename_image, &w, &h); // allocate space for the output image float *out1 = malloc(w*h*sizeof(float)); float *out2 = malloc(w*h*sizeof(float)); float *out3 = malloc(w*h*sizeof(float)); float *out4 = malloc(w*h*sizeof(float)); float *dec1 = malloc(w*h*sizeof(float)); float *dec2 = malloc(w*h*sizeof(float)); float *dec3 = malloc(w*h*sizeof(float)); float *dec4 = malloc(w*h*sizeof(float)); // creer les images translatees apply_translation(dec1, 1, 0, im, w, h); apply_translation(dec2, 0, 1, im, w, h); apply_translation(dec3, -1, 1, im, w, h); apply_translation(dec4, -1, -1, im, w, h); // calculer les derivees for(int j = 0 ; j < h ; j++) for(int i = 0 ; i < w ; i++) { out1[j*w+i] = (dec1[j*w+i] - im[j*w+i])*(dec1[j*w+i] - im[j*w+i]); out2[j*w+i] = (dec2[j*w+i] - im[j*w+i])*(dec2[j*w+i] - im[j*w+i]); out3[j*w+i] = (dec3[j*w+i] - im[j*w+i])*(dec3[j*w+i] - im[j*w+i])/2; out4[j*w+i] = (dec4[j*w+i] - im[j*w+i])*(dec4[j*w+i] - im[j*w+i])/2; } // save the output image iio_save_image_float(filename_der1, out1, w, h); iio_save_image_float(filename_der2, out2, w, h); iio_save_image_float(filename_der3, out3, w, h); iio_save_image_float(filename_der4, out4, w, h); // cleanup and exit free(im); free(out1); free(out2); free(out3); free(out4); free(dec1); free(dec2); free(dec3); free(dec4); return 0; }
int main_rpc_pm(int c, char *v[]) { TIFFSetWarningHandler(NULL);//suppress warnings // input arguments if (c < 9 || 0 == c%2) { fprintf(stderr, "usage:\n\t" "%s (a.{tiff,rpc})+ ax ay in.tif out.tif\n", *v); //0 1 2 c-4 c-3 c-2 c-1 return 1; } int n = (c - 5) / 2; double axyh[3] = {atof(v[c-4]), atof(v[c-3]), 0}; char *filename_h0 = v[c-2]; char *filename_out = v[c-1]; char *filename_img[n]; char *filename_rpc[n]; for (int i = 0; i < n; i++) { filename_img[i] = v[1 + 2 * i]; filename_rpc[i] = v[2 + 2 * i]; } fprintf(stderr, "patch matching from %d views\n", n); for (int i = 0; i < n; i++) { fprintf(stderr, "view %d/%d:\n", i+1, n); fprintf(stderr, "\tIMG = %s\n", filename_img[i]); fprintf(stderr, "\tRPC = %s\n", filename_rpc[i]); } // read input images int megabytes = 800/n; struct tiff_tile_cache t[n]; for (int i = 0; i < n; i++) tiff_tile_cache_init(t + i, filename_img[i], megabytes); int pd = t->i->spp; for (int i = 0; i < n; i++) if (pd != t[i].i->spp) fail("image %d color depth mismatch\n", i); // read input rpcs struct rpc r[n]; for (int i = 0; i < n; i++) read_rpc_file_xml(r + i, filename_rpc[i]); // read initialized raster int w, h; float *in_h0 = iio_read_image_float(filename_h0, &w, &h); // allocate space for output raster float *out_h = xmalloc(w * h * sizeof*out_h); // run the algorithm pm_rpcn(out_h, in_h0, w, h, t, r, n, axyh); // save the output raster iio_save_image_float(filename_out, out_h, w, h); // cleanup and exit free(in_h0); free(out_h); return 0; }
int main(int argc, char **argv) { // process input arguments if (argc != 6) { fprintf(stderr, "usage: \n \t imageIn n hom imageOut parameter \n"); return 0; } char *filename_ImgIn = argv[1]; int n = atoi(argv[2]); char *hom = argv[3]; char *filename_ImgOut = argv[4]; float delta = atof(argv[5]); char filename_hom[n*n][256]; int nn = n*n; int w, h; float *im = iio_read_image_float(filename_ImgIn, &w, &h); float H[nn*9]; float *coordx = malloc(n*n*sizeof(float)); float *coordy = malloc(n*n*sizeof(float)); coordinates_centers(w, h, n, coordx, coordy); for(int i = 0 ; i < nn ; i++) { sprintf(filename_hom[i], "%s_%d.txt", hom, i+1); FILE* f = NULL; f = fopen(filename_hom[i], "r"); if (f != NULL) { fscanf(f, "%f %f %f %f %f %f %f %f %f", &H[9*i+0], &H[9*i+1], &H[9*i+2], &H[9*i+3], &H[9*i+4], &H[9*i+5], &H[9*i+6], &H[9*i+7], &H[9*i+8]); fclose(f); } else { printf("Impossible to open file"); } } float *out = malloc(w*h*sizeof(float)); float *Tx = malloc(w*h*sizeof(float)); float *Ty = malloc(w*h*sizeof(float)); delta = delta*(w+h)/(n+2); compute_transformation(n, coordx, coordy, H, Tx, Ty, w, h, delta); apply_transformation(im, Tx, Ty, w, h, out); iio_save_image_float(filename_ImgOut, out, w, h); free(out); free(Tx); free(Ty); free(coordx); free(coordy); return 0; }