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_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[]) { bool do_invert = pick_option(&c, &v, "i", NULL); int order = atoi(pick_option(&c, &v, "o", "-3")); if (c < 4 || c > 6) return fprintf(stderr, "usage:\n\t" "%s [-i] [-o {0|1|2|-3|3|5|7}] hom w h [in [out]]\n" //0 1 2 3 4 5 "\t-i\tinvert input homography\n" "\t-o\tchose interpolation order (default -3 = bicubic)\n" , *v); double H_direct[9], H_inv[9]; read_n_doubles_from_string(H_direct, v[1], 9); invert_homography(H_inv, H_direct); double *H = do_invert ? H_inv : H_direct; int ow = atoi(v[2]); int oh = atoi(v[3]); char *filename_in = c > 4 ? v[4] : "-"; char *filename_out = c > 5 ? v[5] : "-"; int w, h, pd; float *x = iio_read_image_float_split(filename_in, &w, &h, &pd); float *y = xmalloc(ow * oh * pd * sizeof*y); int r = 0; for (int i = 0; i < pd; i++) r += shomwarp(y + i*ow*oh, ow, oh, H, x + i*w*h, w, h, order); iio_save_image_float_split(filename_out, y, ow, oh, pd); return r; }
int main(int c, char *v[]) { if (c < 4 || c > 6) return fprintf(stderr, "usage:\n\t" "%s [-i {0|1|2|3}] hom w h [in [out]]\n", *v); // 0 1 2 3 4 5 double H[9]; read_n_doubles_from_string(H, v[1], 9); int ow = atoi(v[2]); int oh = atoi(v[3]); char *filename_in = c > 4 ? v[4] : "-"; char *filename_out = c > 5 ? v[5] : "-"; int w, h, pd; float *x = iio_read_image_float_split(filename_in, &w, &h, &pd); float *y = xmalloc(ow * oh * pd * sizeof*y); for (int i = 0; i < pd; i++) homwarp(y + i*ow*oh, ow, oh, H, x + i*w*h, w, h); iio_save_image_float_split(filename_out, y, ow, oh, pd); return 0; }
int main(int c, char *v[]) { if (c != 5 && c != 6 && c != 7) { fprintf(stderr, "usage:\n\t" "%s Axyz.tiff Bxyx.tiff homA homB [pairs2d [pairs3d]]\n",*v); //0 1 2 3 4 5 6 return 1; } char *filename_a = v[1]; char *filename_b = v[2]; char *homstring_a = v[3]; char *homstring_b = v[4]; char *filename_in = c > 5 ? v[5] : "-"; char *filename_out = c > 6 ? v[6] : "-"; double Ha[9], Hb[9], iHa[3][3], iHb[3][3]; int nHa = read_n_doubles_from_string(Ha, homstring_a, 9); int nHb = read_n_doubles_from_string(Hb, homstring_b, 9); if (nHa != 9) set_identity(Ha); if (nHb != 9) set_identity(Hb); invert_homography(iHa, (void*)Ha); invert_homography(iHb, (void*)Hb); int wa, ha, pda, wb, hb, pdb; float *a = iio_read_image_float_vec(filename_a, &wa, &ha, &pda); float *b = iio_read_image_float_vec(filename_b, &wb, &hb, &pdb); FILE *fi = xfopen(filename_in, "r"); FILE *fo = xfopen(filename_out, "w"); if (pda != pdb) return fprintf(stderr, "input images dimension mismatch\n"); if (pda != 1 && pda != 3) return fprintf(stderr, "input images should be h or xyz\n"); int n, lmax = 10000; char line[lmax]; while (n = getlinen(line, lmax, fi)) { double m[4], p[2], q[2]; int r = sscanf(line, "%lf %lf %lf %lf", m, m + 1, m + 2, m + 3); if (r != 4) continue; apply_homography(p, iHa, m); apply_homography(q, iHb, m + 2); int ia = lrint(p[0]); int ja = lrint(p[1]); int ib = lrint(q[0]); int jb = lrint(q[1]); if (!insideP(wa, ha, ia, ja)) continue; if (!insideP(wb, hb, ib, jb)) continue; float *va = a + pda * (wa * ja + ia); float *vb = b + pda * (wb * jb + ib); if (!isfinite(*va)) continue; if (!isfinite(*vb)) continue; if (pda == 1) // heights fprintf(fo, "%lf %lf %lf %lf %lf %lf\n", p[0], p[1], *va, q[0], q[1], *vb); else // xyz fprintf(fo, "%lf %lf %lf %lf %lf %lf\n", va[0], va[1], va[2], vb[0], vb[1], vb[2]); } free(a); free(b); xfclose(fo); xfclose(fi); return 0; }