// 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 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; }
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 != 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; poisson_extension_steps(out, inpu, data, *w, *h); iio_save_image_float(filename_out, out, *w, *h); 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 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(int c, char *v[]) { if (c != 8) { fprintf(stderr, "usage:\n\t" "%s inpat.png first last sigma side nwarps epsilon\n", *v); // 0 1 2 3 4 5 6 7 return EXIT_FAILURE; } char *inpat = v[1]; int first_frame = atoi(v[2]); int last_frame = atoi(v[3]); float sigma = atof(v[4]); int side = atoi(v[5]); int nwarps = atoi(v[6]); float epsilon = atof(v[7]); int w, h, n; float **x = read_images(&n, &w, &h, inpat, first_frame, last_frame); assert(n == abs(first_frame - last_frame)); float *y = xmalloc(w * h * sizeof*y); frakes_monaco_smith(y, x, w, h, n, sigma, side, nwarps, epsilon); iio_save_image_float("-", y, w, h); for (int i = 0; i < n; i++) free(x[i]); free(x); free(y); return EXIT_SUCCESS; }
int main(int c, char *v[]) { if (c != 10 && c != 11) { fprintf(stderr, "usage:\n\t" "%s w h p r1 r2 c1 c2 x0 y0 [out.png]\n", *v); // 0 1 2 3 4 5 6 7 8 9 10 return 1; } int w = atoi(v[1]); int h = atoi(v[2]); float p = atof(v[3]); float r1 = atof(v[4]); float r2 = atof(v[5]); float c1 = atof(v[6]); float c2 = atof(v[7]); float x0 = atof(v[8]); float y0 = atof(v[9]); char *filename_out = c > 10 ? v[10] : "-"; float *x = xmalloc(w*h*sizeof*x); radphar(x, w, h, p, r1, r2, c1, c2, x0, y0); iio_save_image_float(filename_out, x, w, h); free(x); 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_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 c, char *v[]) { if (c != 8) { fprintf(stderr, "usage:\n\t" "%s a.png b.png \"fm\" out_disp out_err ini rad\n", *v); // 0 1 2 3 4 5 6 7 return 1; } char *filename_a = v[1]; char *filename_b = v[2]; char *fm_text = v[3]; char *filename_out_disp = v[4]; char *filename_out_err = v[5]; char *filename_init = v[6]; float maxradius = atof(v[7]); int nfm; float *ffm = alloc_parse_floats(9, fm_text, &nfm); if (nfm != 9) fail("expects a fundamental matrix (9 numbers)"); double fm[9]; for (int i = 0; i < 9; i++) fm[i] = ffm[i]; free(ffm); int w, h, pd, ww, hh, ppdd; float *a = iio_read_image_float_vec(filename_a, &w, &h, &pd); float *b = iio_read_image_float_vec(filename_b, &ww, &hh, &ppdd); if (w != ww || h != hh || pd != ppdd) fail("input images size mismatch"); float *o = xmalloc(w*h*3*sizeof*o); float *e = xmalloc(w*h*sizeof*o); float *rad = xmalloc(w*h*sizeof*o); for (int i = 0; i < w*h; i++) rad[i] = maxradius; float *i = NULL; if (0 != strcmp(filename_init, "0")) { i = iio_read_image_float_vec(filename_init, &ww, &hh, &ppdd); if (w != ww || h != hh) fail("init image size mismatch"); if (ppdd != 2) fail("init file must be a vector field"); } bmfm_fancy(o, e, a, b, w, h, pd, fm, i, rad); iio_save_image_float_vec(filename_out_disp, o, w, h, 2); iio_save_image_float(filename_out_err, e, w, h); free(a); free(b); free(o); free(e); if (i) free(i); return 0; }
static void save_debug_image(char *fpat, int id, float *x, int w, int h) { return; char filename[0x100]; snprintf(filename, 0x100, fpat, id); fprintf(stderr, "saving image \"%s\"\n", filename); iio_save_image_float(filename, x, w, h); }
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 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_save_image_float(filename_out, x, w, 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; }
/** * * Main program: * This program reads the following parameters from the console and * then computes the optical flow: * I_1 Previous image to I0 * I0 first image * I1 second image * I0_Smoothed Image for using with function g * out name of the output flow field * outOcc name of the output occlusion map * nprocs number of threads to use (OpenMP library) * tauEta Time step in the primal-dual scheme for eta variable * tauChi Time step in the primal-dual scheme for chi variable * lambda Data term weight parameter * alpha Length term weight parameter (in the occlusion region) * beta Negative divergence data Term * theta tightness parameter * nscales number of scales in the pyramidal structure * zfactor downsampling factor for creating the scales * nwarps number of warps per scales * epsilon stopping criterion threshold for the iterative process * verbose switch on/off messages * */ int main(int argc, char *argv[]) { if (argc < 3) { fprintf(stderr, "Usage: %s I_1 I0 I1 [I0_Smoothed out " // 0 1 2 3 4 5 "outOcc nproc lambda alpha beta theta nscales zfactor nwarps epsilon " // 6 7 8 9 10 11 12 13 14 15 "verbose ]\n", *argv); // 16 return EXIT_FAILURE; } // Variable Declaration double *u1=NULL, *u2=NULL; //field double *chi=NULL; //Occlussion map double *I_1=NULL, *I0=NULL, *I1=NULL; // Previous (I_1), current (I0) and next image (I1) double *filtI0=NULL; //Filtered image used in function g int nx_1, ny_1, nx, ny, nx1, ny1, nxf, nyf; //Image sizes //read the parameters int i = 1; char* image_1_name = argv[i]; i++; //1 char* image1_name = argv[i]; i++; //2 char* image2_name = argv[i]; i++; //3 char* image1_Smooth_name = (argc>i) ? argv[i] : argv[2]; i++; //4 If there is no I0_Smoothed, then it will be I0 const char* outfile = (argc>i)? argv[i]: PAR_DEFAULT_OUTFLOW; i++; //5 const char* outOccFile = (argc>i)? argv[i]: PAR_DEFAULT_OUT_OCC; i++; //6 int nproc = (argc>i)? atoi(argv[i]): PAR_DEFAULT_NPROC; i++; //7 double lambda = (argc>i)? atof(argv[i]): PAR_DEFAULT_LAMBDA; i++; //8 double alpha = (argc>i)? atof(argv[i]): PAR_DEFAULT_ALPHA; i++; //9 double betaW = (argc>i)? atof(argv[i]): PAR_DEFAULT_BETA; i++; //10 double theta = (argc>i)? atof(argv[i]): PAR_DEFAULT_THETA; i++; //11 int nscales = (argc>i)? atoi(argv[i]): PAR_DEFAULT_NSCALES; i++; //12 double zfactor = (argc>i)? atof(argv[i]): PAR_DEFAULT_ZFACTOR; i++; //13 int nwarps = (argc>i)? atoi(argv[i]): PAR_DEFAULT_NWARPS; i++; //14 double epsilon = (argc>i)? atof(argv[i]): PAR_DEFAULT_EPSILON; i++; //15 int verbose = (argc>i)? atoi(argv[i]): PAR_DEFAULT_VERBOSE; i++; //16 //check parameters if (nproc < 0) { nproc = PAR_DEFAULT_NPROC; fprintf(stderr, "warning: " "nproc changed to %d\n", nproc); } if (lambda <= 0) { lambda = PAR_DEFAULT_LAMBDA; fprintf(stderr, "warning: " "lambda changed to %g\n", lambda); } if (alpha <= 0) { alpha = PAR_DEFAULT_ALPHA; fprintf(stderr, "warning: " "alpha changed to %g\n", alpha); } if (betaW <= 0) { betaW = PAR_DEFAULT_BETA; fprintf(stderr, "warning: " "beta changed to %g\n", betaW); } if (theta <= 0) { theta = PAR_DEFAULT_THETA; if (verbose) fprintf(stderr, "warning: " "theta changed to %g\n", theta); } if (nscales <= 0) { nscales = PAR_DEFAULT_NSCALES; fprintf(stderr, "warning: " "nscales changed to %d\n", nscales); } if (zfactor <= 0 || zfactor >= 1) { zfactor = PAR_DEFAULT_ZFACTOR; fprintf(stderr, "warning: " "zfactor changed to %g\n", zfactor); } if (nwarps <= 0) { nwarps = PAR_DEFAULT_NWARPS; fprintf(stderr, "warning: " "nwarps changed to %d\n", nwarps); } if (epsilon <= 0) { epsilon = PAR_DEFAULT_EPSILON; fprintf(stderr, "warning: " "epsilon changed to %f\n", epsilon); } #ifdef _OPENMP if (nproc > 0) omp_set_num_threads(nproc); #endif//DISABLE_OMP // read the input images I_1 = read_image(image_1_name, &nx_1, &ny_1); I0 = read_image(image1_name, &nx, &ny); I1 = read_image(image2_name, &nx1, &ny1); filtI0 = read_image(image1_Smooth_name, &nxf, &nyf); if(nx==nx_1 && nx==nx1 && nx==nxf && ny==ny_1 && ny==ny1 && ny==nyf) { //Set the number of scales according to the size of the //images. The value N is computed to assure that the smaller //images of the pyramid don't have a size smaller than 16x16 const int N = floor(log((float)MIN(nx, ny)/16.0)/log(1./zfactor)) + 1; if (N < nscales) nscales = N; if (verbose) fprintf(stderr, " nproc=%d \n lambda=%f \n alpha=%f \n" " beta=%f \n theta=%f \n nscales=%d \n zfactor=%f\n nwarps=%d \n epsilon=%g\n", nproc, lambda, alpha, betaW, theta, nscales, zfactor, nwarps, epsilon); //allocate memory for the flow u1 = (double *)xmalloc( nx * ny * sizeof(double)); u2 = (double *)xmalloc( nx * ny * sizeof(double)); //and the occlusion map chi = (double *)xmalloc( nx * ny * sizeof(double)); for(int i=0; i<nx*ny; i++) { chi[i] = 0.0; u1[i] = 0.0; u2[i] = 0.0; } //compute the optical flow Dual_TVL1_optic_flow_multiscale( I_1, I0, I1, filtI0, u1, u2, chi, nx, ny, lambda, alpha, betaW, theta, nscales, zfactor, nwarps, epsilon, verbose); //write_flow(u1, u2, nx, ny); //<----Eliminar en la version fina a entregar. Solo esta para propositos de depuraci—n. //save the optical flow float *f = (float *)malloc(sizeof(float) * nx * ny * 2); for (int i = 0; i < nx * ny; i++) { f[2*i] = (float)u1[i]; //Avoid the cast! f[2*i+1] = (float)u2[i]; //Avoid the cast! } iio_save_image_float_vec((char *)outfile, f, nx, ny, 2); free(f); //save the occlusions /* int iv=0; FILE * fid=fopen(outOccFile, "w"); for (int i=0; i<ny; i++) { for (int j=0; j<nx; j++) { fprintf(fid, " %f", chi[iv]); iv++; } fprintf(fid, " \n"); } fclose(fid);*/ //iio_save_image_double((char *)outOccFile, chi, nx, ny); float *fOcc = (float *)malloc(sizeof(float) * nx * ny ); for (int i = 0; i < nx * ny; i++) { fOcc[i] = (float)chi[i]*255; //Avoid the cast! } iio_save_image_float((char *)outOccFile, fOcc, nx, ny); free(fOcc); } //delete allocated memory free(I0); free(I1); free(u1); free(u2); free(filtI0); free(chi); return EXIT_SUCCESS; }
// 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; }