예제 #1
0
int main(int c, char *v[])
{
	if (c != 5) {
		fprintf(stderr, "usage:\n\t%s rpca rpcb  ssf h > err.uv\n", *v);
		//                          0 1    2     3   4
		return 1;
	}
	struct rpc ra[1]; read_rpc_file_xml(ra, v[1]);
	struct rpc rb[1]; read_rpc_file_xml(rb, v[2]);
	int f = atoi(v[3]);
	double h = atof(v[4]);
	int nx = (ra->dmval[2] - ra->dmval[0])/f;
	int ny = (ra->dmval[3] - ra->dmval[1])/f;
	fprintf(stderr, "will build image of size %dx%d\n", nx, ny);
	float (*e)[nx][2] = xmalloc(2*nx*ny*sizeof(float));
	for (int j = 0; j < ny; j++)
	for (int i = 0; i < nx; i++)
	{
		double fij[2] = {ra->dmval[0] + f*i, ra->dmval[1] + f*j};
		double tij[2], rij[2];
		eval_rpc_pair(tij, ra, rb, fij[0], fij[1], h);
		eval_rpc_pair(rij, rb, ra, tij[0], tij[1], h);
		e[j][i][0] = rij[0] - fij[0];
		e[j][i][1] = rij[1] - fij[1];

	}
	iio_save_image_float_vec("-", **e, nx, ny, 2);
	return 0;
}
예제 #2
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;
}
예제 #3
0
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;
}
예제 #4
0
파일: rpcflow.c 프로젝트: Fahdben/imscript
int main(int c, char *v[])
{
	if (c != 11 && c != 10) {
		fprintf(stderr, "usage:\n\t"
			"%s rpca rpcb a0x a0y aw ah b0x b0y h [flow]"
		//        0 1    2    3   4   5  6  7   8   9  10
			"\n", *v);
		return EXIT_FAILURE;
	}
	char *filename_rpca = v[1];
	char *filename_rpcb = v[2];
	int offset_a[2] = {atoi(v[3]), atoi(v[4])};
	int size_a[2] = {atoi(v[5]), atoi(v[6])};
	int offset_b[2] = {atoi(v[7]), atoi(v[8])};
	double hbase = atof(v[9]);
	char *filename_flow = c > 10 ? v[10] : "-";

	struct rpc rpca[1]; read_rpc_file_xml(rpca, filename_rpca);
	struct rpc rpcb[1]; read_rpc_file_xml(rpcb, filename_rpcb);

	int w = size_a[0];
	int h = size_a[1];
	float (*f)[w][2] = xmalloc(w * h * 2 * sizeof(float));
	for (int j = 0; j < h; j++)
	for (int i = 0; i < w; i++)
	{
		double x[2] = {offset_a[0] + i, offset_a[1] + j}, r[2];
		eval_rpc_pair(r, rpca, rpcb, x[0], x[1], hbase);
		double ox[2] = {r[0] - offset_b[0], r[1] - offset_b[1]};
		f[j][i][0] = ox[0] + offset_a[0] - x[0];
		f[j][i][1] = ox[1] + offset_a[1] - x[1];
		//fprintf(stderr, "i=(%d %d) x=(%g %g) ox=(%g %g) f=(%g %g)\n",
		//		i, j,
		//		x[0], x[1],
		//		ox[0], ox[1],
		//		f[j][i][0], f[j][i][1]);
	}

	iio_save_image_float_vec(filename_flow, f[0][0], w, h, 2);

	return 0;
}
예제 #5
0
파일: rpc_pmn.c 프로젝트: Fahdben/imscript
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;
}
예제 #6
0
파일: disp2ply.c 프로젝트: mnhrdt/s2p
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;
}