Exemplo n.º 1
0
int main_synflow(int c, char *v[])
{
	if (c != 6) {
		fprintf(stderr, "usage:\n\t%s model \"params\""
				//         0  1       2
				" in out flow\n", *v);
				//3  4   5
		return EXIT_FAILURE;
	}

	int w, h, pd;
	float *x = iio_read_image_float_vec(v[3], &w, &h, &pd);

	float *y = xmalloc(w * h * pd * sizeof*y);
	float *f = xmalloc(w * h * 2 * sizeof*y);

	int maxparam = 40;
	double param[maxparam];
	int nparams = parse_doubles(param, maxparam, v[2]);

	struct flow_model fm[1];
	produce_flow_model(fm, param, nparams, v[1], w, h);
	fill_flow_field(f, fm, w, h);
	transform_forward(y, fm, x, w, h, pd);

	iio_save_image_float_vec(v[4], y, w, h, pd);
	iio_save_image_float_vec(v[5], f, w, h, 2);

	free(x);
	free(y);
	free(f);

	return EXIT_SUCCESS;
}
Exemplo n.º 2
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;
}
Exemplo n.º 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;
}
Exemplo n.º 4
0
// deinterlace and produce two images
int main(int c, char *v[])
{
	if (c != 4) {
		fprintf(stderr, "usage:\n\t%s in out1 out2\n", *v);
		//                          0 1  2    3
		return EXIT_FAILURE;
	}

	int w, h, pd;
	void *xx = iio_read_image_float_vec(v[1], &w, &h, &pd);
	float (*x)[w][pd] = xx;
	float (*y)[w][pd] = calloc(w*h*pd,sizeof(float));
	float (*z)[w][pd] = calloc(w*h*pd,sizeof(float));

	for (int j = 1; j < h; j += 2) {
		for (int i = 0; i < w; i++)
		for (int l = 0; l < pd; l++)
			z[j][i][l] = x[j][i][l];
		if (j+2 < h)
			for (int i = 0; i < w; i++)
			for (int l = 0; l < pd; l++)
				z[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
	}
	for (int j = 0; j < h; j += 2) {
		for (int i = 0; i < w; i++)
		for (int l = 0; l < pd; l++)
			y[j][i][l] = x[j][i][l];
		if (j+2 < h)
			for (int i = 0; i < w; i++)
			for (int l = 0; l < pd; l++)
				y[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
	}

	// the other way to interpet it:
//	for (int j = 0; j < h-1; j += 2) {
//		for (int i = 0; i < w; i++)
//		for (int l = 0; l < pd; l++)
//			z[j][i][l] = x[j+1][i][l];
//		if (j+3 < h)
//			for (int i = 0; i < w; i++)
//			for (int l = 0; l < pd; l++)
//				z[j+1][i][l] = (x[j+1][i][l] + x[j+3][i][l])/2;
//	}
//	for (int j = 0; j < h; j += 2) {
//		for (int i = 0; i < w; i++)
//		for (int l = 0; l < pd; l++)
//			y[j][i][l] = x[j][i][l];
//		if (j+2 < h)
//			for (int i = 0; i < w; i++)
//			for (int l = 0; l < pd; l++)
//				y[j+1][i][l] = (x[j][i][l] + x[j+2][i][l])/2;
//	}

	iio_save_image_float_vec(v[2], y[0][0], w, h, pd);
	iio_save_image_float_vec(v[3], z[0][0], w, h, pd);

	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
int main(int c, char *v[])
{
	// process input arguments
	if (c < 12 || c > 14 ) {
		fprintf(stderr, "usage:\n\t"
			"%s h1 ... h9 W H [in.png [out.tiff]]\n", *v);
		//       0  1      9  10 11 12      13
		return 1;
	}
	double H[9]; for (int i = 0; i < 9; i++) H[i] = atof(v[1+i]);
	int out_w = atoi(v[10]);
	int out_h = atoi(v[11]);
	char *filename_in  = c > 12 ? v[12] : "-";
	char *filename_out = c > 13 ? v[13] : "-";

	// read input image
	int w, h, pd;
	float *x = iio_read_image_float_vec(filename_in, &w, &h, &pd);

	// allocate space for output image
	float *y = malloc(out_w * out_h * pd * sizeof*y);
	if (!y) return 2;

	// perform the computation
	homdots(y, out_w, out_h, x, w, h, pd, H);

	// save output result
	iio_save_image_float_vec(filename_out, y, out_w, out_h, pd);

	// cleanup and exit
	free(x);
	free(y);
	return 0;
}
int main(int argc, char *argv[]) {

    double sigma_r = 30.0;
    double sigma_d = 3.0;
    const char * filename_in = "../../data/Lena.ppm";

    if (argc > 1)   filename_in = argv[1];
    if (argc > 2)   sigma_r = atof(argv[2]);
    if (argc > 3)   sigma_d = atof(argv[3]);
    
    char filename_out[100];
    sprintf(filename_out,"%s.color.out.png",filename_in);

    int w = 0;
    int h = 0;
    int nch = 0;

    float *img_in = iio_read_image_float_vec(filename_in, &w, &h, &nch);

    float *img_out = malloc(w * h * nch * sizeof (float));

    bilateral_rgb_3(img_in, img_out, w, h, nch, sigma_r, sigma_d);

    iio_save_image_float_vec( filename_out, img_out, w, h, nch);

    free(img_in);
    free(img_out);

    return 0;
}
Exemplo n.º 7
0
int main(int c, char *v[])
{
	if (c < 5 || c > 7) {
		fprintf(stderr, "usage:\n\t%s x0 y0 xf yf [in [out]]\n", *v);
		//                          0 1  2  3  4   5   6
		return EXIT_FAILURE;
	}
	int x0 = atoi(v[1]);
	int y0 = atoi(v[2]);
	int xf = atoi(v[3]);
	int yf = atoi(v[4]);
	char *filename_in = c > 5 ? v[5] : "-";
	char *filename_out = c > 6 ? v[6] : "-";

	int w, h, pd;
	float *image_in = iio_read_image_float_vec(filename_in, &w, &h, &pd);
	float *image_out = xmalloc(w*h*pd*sizeof*image_out);

	int cw, ch;
	crop(image_out, &cw, &ch, image_in, w, h, pd,
			x0, y0, xf, yf);

	iio_save_image_float_vec(filename_out, image_out, cw, ch, pd);
	return EXIT_SUCCESS;
}
Exemplo n.º 8
0
int main(int c, char *v[])
{
	if (c != 4 && c != 5 && c != 6) {
		fprintf(stderr, "usage:\n\t%s w h pd [in [out]]\n", *v);
		return 1;
	}
	int w, ow = atoi(v[1]);
	int h, oh = atoi(v[2]);
	int pd, opd = atoi(v[3]);
	char *fname_in = c > 4 ? v[4] : "-";
	char *fname_out = c > 5 ? v[5] : "-";

	//int w, h, pd;
	//float *x = iio_read_image_float_vec(fname, &w, &h, &pd);
	//printf("%d %d %d\n", w, h, pd);


	float *x = iio_read_image_float_vec(fname_in, &w, &h, &pd);
	float (*y)[ow][opd] = malloc(ow * oh * opd * sizeof(float));
	if (!y) error("out of mem");

	extension_operator_float p = extend_float_image_by_zero;
	for (int j = 0; j < oh; j++)
	for (int i = 0; i < ow; i++)
	for (int l = 0; l < opd; l++)
		y[j][i][l] = p(x, w, h, pd, i, j, l);

	iio_save_image_float_vec(fname_out, y[0][0], ow, oh, opd);

	free(x);
	free(y);

	return 0;
}
Exemplo n.º 9
0
int main(int c, char *v[])
{
	// process input arguments
	if (c != 3) {
		fprintf(stderr, "usage:\n\t"
				"%s [options] image transform\n", *v);
		//               0            1      2
		return 1;
	}
	int nrho = atoi(v[1]);
	int ntheta = atoi(v[2]);

	// read input gradient
	int w, h, pd;
	float *gradient = iio_read_image_float_vec("-", &w, &h, &pd);
	if (pd != 2) return fprintf(stderr, "I expect a gradient!\n");

	// compute transform
	float *transform = malloc(nrho * ntheta * sizeof*transform);
	ghough(transform, nrho, ntheta, gradient, w, h);

	// save output image
	iio_save_image_float_vec("-", transform, nrho, ntheta, 1);

	// cleanup and exti
	free(gradient);
	free(transform);
	return 0;
}
Exemplo n.º 10
0
static int main_puts(int c, char **v)
{
	int kerning = atoi(pick_option(&c, &v, "k", "0"));
	char *colorname = pick_option(&c, &v, "c", "000");
	if (c != 5 && c != 6 && c != 7) {
		fprintf(stderr, "usage:\n\t"
			"%s font.bdf px py \"string\" [in [out]]\n", *v);
		//        0  1       2  3    4         5   6
		return 1;
	}
	char *bdf = v[1];
	int px = atoi(v[2]);
	int py = atoi(v[3]);
	char *text = v[4];
	char *filename_in = c > 5 ? v[5] : "-";
	char *filename_out = c > 6 ? v[6] : "-";

	struct bitmap_font f;
	font_fill_from_bdf(&f, bdf);

	int w, h, pd;
	float *x = iio_read_image_float_vec(filename_in, &w, &h, &pd);

	float color[10] = {0};
	if (pd == (int)strlen(colorname))
		for (int i = 0; i < pd; i++)
			color[i] = (unsigned char)((255*(colorname[i]-'0'))/8);
	put_string_in_float_image(x, w,h,pd, px,py, color, kerning, &f, text);

	iio_save_image_float_vec(filename_out, x, w, h, pd);

	free(f.data);
	free(x);
	return 0;
}
Exemplo n.º 11
0
int main(int c, char *v[])
{
	// extract optional parameters
	bool folding    = pick_option(&c, &v, "f", NULL);
	char *fname_in  = pick_option(&c, &v, "i", "-");
	char *fname_out = pick_option(&c, &v, "o", "-");

	// process input arguments
	if (c != 3) {
		fprintf(stderr, "usage:\n\t"
				"%s nrho ntheta <gradient >hough\n", *v);
		//               0  1    2
		return 1;
	}
	int nrho = atoi(v[1]);
	int ntheta = atoi(v[2]);

	// read input gradient
	int w, h, pd;
	float *gradient = iio_read_image_float_vec(fname_in, &w, &h, &pd);
	if (pd != 2) return fprintf(stderr, "I expect a gradient!\n");

	// compute transform
	float *transform = malloc(nrho * ntheta * sizeof*transform);
	ghough(transform, nrho, ntheta, gradient, w, h, folding);

	// save output image
	iio_save_image_float_vec(fname_out, transform, nrho, ntheta, 1);

	// cleanup and exti
	free(gradient);
	free(transform);
	return 0;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
int main(int c, char *v[]) {

    if (c!=3) {
        printf("Usage: %s input_image output_image\n",v[0]);
    } else {
        int w, h, pixeldim;
        float *x = iio_read_image_float_vec(v[1], &w, &h, &pixeldim);
        fprintf(stderr, "Got a %dx%d image with %d channels\n", w, h, pixeldim);

        // some processing here
        float *xgray = malloc(w*h*sizeof(float));
        if (pixeldim==3) {
            int i;
            for(i=0; i<w*h; i++) {
                xgray[i] =  (6968*x[pixeldim*i] + 23434*x[pixeldim*i + 1] + 2366*x[pixeldim*i + 2])/32768;
            }
            // Y = (6968 R + 23434 G + 2366 B) / 32768
        }
        else {
            xgray = x;
        }

        printf("w = %d, h = %d, pixeldim = %d.\n",w,h,pixeldim);

        iio_save_image_float_vec(v[2], xgray, w, h, 1);
        free(x);
        return 0;
    }

}
Exemplo n.º 14
0
int main(int c, char *v[])
{
	// process input arguments
	if (c < 10 || c > 13 ) {
		fprintf(stderr, "usage:\n\t"
			"%s a b p c d q W H ord [in.png [out.png]]\n", *v);
		//       0  1 2 3 4 5 6 7 8  9   10      11
		return 1;
	}
	double A[6]; for (int i = 0; i < 6; i++) A[i] = atof(v[1+i]);
	int out_w = atoi(v[7]);
	int out_h = atoi(v[8]);
	int order = atoi(v[9]);
	char *filename_in  = c > 10 ? v[10] : "-";
	char *filename_out = c > 11 ? v[11] : "-";

	// read input image
	int w, h, pd;
	float *x = iio_read_image_float_vec(filename_in, &w, &h, &pd);

	// allocate space for output image
	float *y = malloc(out_w * out_h * pd * sizeof*y);
	if (!y) return 2;

	// perform the computation
	naive_affine_map_using_spline(y, out_w, out_h, x, w, h, pd, A, order);

	// save output result
	iio_save_image_float_vec(filename_out, y, out_w, out_h, pd);

	// cleanup and exit
	free(x);
	free(y);
	return 0;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
// main function
int main(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 (assume they have the same size, do not check)
	int w, h, pd;
	float *left  = iio_read_image_float_vec(filename_left , &w, &h, &pd);
	float *right = iio_read_image_float_vec(filename_right, &w, &h, &pd);

	// allocate space for the output image
	float *out = malloc(w*h*pd*sizeof(float));

	// run the algorithm
	cregistration(out, left, right, w, h, pd);

	// save the output image
	iio_save_image_float_vec(filename_Tright, out, w, h, pd);

	// cleanup and exit
	free(left);
	free(right);
	free(out);
	return 0;
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
0
int main(int c, char *v[])
{
	// treat input arguments
	if (c != 8) {
		fprintf(stderr, "usage:\n\t"
				"%s spec.txt bg_a bg_b bg_f o_a o_b o_f\n", *v);
				//0 1        2    3    4    5   6   7
		return 1;
	}
	char *filename_spec  = v[1];
	char *filename_bg_a  = v[2];
	char *filename_bg_b  = v[3];
	char *filename_bg_f  = v[4];
	char *filename_out_a = v[5];
	char *filename_out_b = v[6];
	char *filename_out_f = v[7];

	// read input images
	int w[3], h[3], pd[3];
	float *x = iio_read_image_float_vec(filename_bg_a, w+0, h+0, pd+0);
	float *y = iio_read_image_float_vec(filename_bg_b, w+1, h+1, pd+1);
	float *f = iio_read_image_float_vec(filename_bg_f, w+2, h+2, pd+2);
	if (pd[0] != pd[1] || pd[2] != 2)
		fail("bad pd sequence %d %d %d\n", pd[0], pd[1], pd[2]);

	// allocate output images
	float *ox = xmalloc(w[0] * h[0] * pd[0] * sizeof*ox);
	float *oy = xmalloc(w[0] * h[0] * pd[0] * sizeof*ox);
	float *of = xmalloc(w[0] * h[0] * 2 * sizeof*ox);

	// run thing
	FILE *fs = xfopen(filename_spec, "r");
	overflow_f(fs, ox, oy, of, x, y, f, *w, *h, *pd);
	xfclose(fs);

	// save output
	iio_save_image_float_vec(filename_out_a, ox, *w, *h, *pd);
	iio_save_image_float_vec(filename_out_b, oy, *w, *h, *pd);
	iio_save_image_float_vec(filename_out_f, of, *w, *h, 2);

	// cleanup and exit
	free(x); free(y); free(f);
	free(ox); free(oy); free(of);
	return 0;
}
Exemplo n.º 19
0
// read an image in any format from STDIN and write a ppm to STDOUT
int main(int c, char *v[])
{
	int w, h, pixeldim;
	float *x = iio_read_image_float_split("-", &w, &h, &pixeldim);
	fprintf(stderr, "got a %dx%d image with %d channels\n", w, h, pixeldim);
	iio_save_image_float_vec("-", x, w, h, pixeldim);
	free(x);
	return 0;
}
Exemplo n.º 20
0
int main(int c, char *v[])
{
	char *filename_out = pick_option(&c, &v, "o", "-");
	if (c < 4) {
		fprintf(stderr,
		"usage:\n\t%s {sum|min|max|avg|weisz} [v1 ...] [-o out]\n", *v);
		//          0  1                          2  3
		return EXIT_FAILURE;
	}
	int n = c - 2;
	char *operation_name = v[1];
	void (*f)(float*,float*,int,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, "medi"))   f = float_med;
	if (0 == strcmp(operation_name, "modc"))   f = float_modc;
	if (0 == strcmp(operation_name, "weisz"))   f = float_weisz;
	//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], pd[n];
	for (int i = 0; i < n; i++)
		x[i] = iio_read_image_float_vec(v[i+2], w + i, h + i, pd + i);
	for (int i = 0; i < n; i++) {
		if (w[i] != *w || h[i] != *h || pd[i] != *pd)
			fail("%dth image sizes mismatch\n", i);
	}
	float (*y) = xmalloc(*w * *h * *pd * sizeof*y);
#ifdef _OPENMP
#pragma omp parallel for
#endif
	for (int i = 0; i < *w * *h; i++) {
		float tmp[n][*pd];
		int ngood = 0;
		for (int j = 0; j < n; j++)
			if (isgood(x[j]+i**pd, *pd)) {
				for (int k = 0; k < *pd; k++)
					tmp[ngood][k] = x[j][i**pd+k];
				ngood += 1;
			}
		f(y + i**pd, tmp[0], *pd, ngood);
	}
	iio_save_image_float_vec(filename_out, y, *w, *h, *pd);
	free(y);
	for (int i = 0; i < n; i++)
		free(x[i]);
	return EXIT_SUCCESS;
}
Exemplo n.º 21
0
int main(int argc,char *argv[]){

	if (argc != 11) {
		printf("usage : [image.png] a b p c d q r s t\n"); 
		return 1;
	}
	
	char *filename_in = argv[1];
	
	double H[3][3];
	H[0][0]=strtod(argv[2],NULL);
	H[0][1]=strtod(argv[3],NULL);
	H[0][2]=strtod(argv[4],NULL);
	H[1][0]=strtod(argv[5],NULL);
	H[1][1]=strtod(argv[6],NULL);
	H[1][2]=strtod(argv[7],NULL);
	H[2][0]=strtod(argv[8],NULL);
	H[2][1]=strtod(argv[9],NULL);
	H[2][2]=strtod(argv[10],NULL);

	float *img;
	int w,h,pd;

	img = iio_read_image_float_vec(filename_in, &w, &h, &pd);
	
	float *img_f = malloc(3*WOUT*HOUT*sizeof(float));

	clock_t debutcpu,fincpu;
	double debutreal,finreal;
	debutcpu = clock();
	debutreal = omp_get_wtime();
	if(pd==3){
        apply_homo_final(img,img_f,w,h,WOUT,HOUT,H);
	}else{//suppose pd=1
        float *img3 = malloc(3*w*h*sizeof(float));
        for(int i=0;i<w*h;i++){
            for(int l = 0;l<3;l++){
                img3[3*i+l]=img[i];
            }
        }
        apply_homo_final(img3,img_f,w,h,WOUT,HOUT,H);
	}
	
	fincpu = clock();
	finreal = omp_get_wtime();
	printf("cputime :%fs\ntime : %fs\n",(double)(fincpu-debutcpu)/CLOCKS_PER_SEC,(double)(finreal-debutreal));
	
	iio_save_image_float_vec("img_f.png",img_f,WOUT,HOUT,3);


	return 0;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
0
int main()
{
	int w, h, pd;
	float *y = iio_read_image_float_vec("/tmp/n.png", &w, &h, &pd);
	for (int j = 0; j < h; j++)
	for (int i = 0; i < w-1; i++)
	for (int l = 0; l < pd; l++)
	{
		int idx = ( j*w + i ) * pd + l;
		y[idx] = y[idx+pd] - y[idx];
	}
	iio_save_image_float_vec("ckuza.tiff", y, w, h, pd);
	return 0;
}
Exemplo n.º 24
0
static void dump_warps(float *init_h, int w, int h,
		struct ortho_view *o, int n, char *ident)
{
	int pd = o->t->i->spp;

	for (int k = 0; k < n; k++)
	{
		struct ortho_view *ok = o + k;
		float *w0 = xmalloc(w * h * pd * sizeof(float));
		float *wh = xmalloc(w * h * pd * sizeof(float));

		for (int j = 0; j < h; j++)
		for (int i = 0; i < w; i++)
		{
			int idx = j*w + i;
			double ij0[3] = {i, j, 0};
			double ijh[3] = {i, j, init_h[idx]};
			double p0[3], ph[3];
			project(p0, ok, ij0);
			project(ph, ok, ijh);
			int ip0[2] = {lrint(p0[0]), lrint(p0[1])};
			int iph[2] = {lrint(ph[0]), lrint(ph[1])};
			huge_tiff_getpixel_float(w0+pd*idx,ok->t,ip0[0],ip0[1]);
			huge_tiff_getpixel_float(wh+pd*idx,ok->t,iph[0],iph[1]);
		}

		char buf[FILENAME_MAX];
		snprintf(buf, FILENAME_MAX, "/tmp/pm_%s_%d_w0.tiff", ident, k);
		iio_save_image_float_vec(buf, w0, w, h, pd);
		snprintf(buf, FILENAME_MAX, "/tmp/pm_%s_%d_wh.tiff", ident, k);
		iio_save_image_float_vec(buf, wh, w, h, pd);

		free(w0);
		free(wh);
	}
}
Exemplo n.º 25
0
static void save_debug_flow(char *fpat, int id, float*u, float*v, int w, int h)
{
	return;
	char filename[0x100];
	snprintf(filename, 0x100, fpat, id);
	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];
	}

	fprintf(stderr, "saving field \"%s\"\n", filename);
	iio_save_image_float_vec(filename, f, w, h, 2);
	xfree(f);
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
0
// API: close a fancy image
void fancy_image_close(struct fancy_image *fi)
{
	struct FI *f = (void*)fi;

	if (f->tiffo)
		tiff_octaves_free(f->t);
	else {
		if ((f->option_write && f->x_changed) || f->option_creat)
			iio_save_image_float_vec(f->x_filename, f->x,
					f->w, f->h, f->pd);
		if (f->no > 1)
			free_pyramid(f);
		else
			free(f->x);
	}
	free(f);
}
Exemplo n.º 28
0
int main(int c, char *v[])
{
	if (c != 1 && c != 2 && c != 3) {
		fprintf(stderr, "usage:\n\t%s [in [out]]\n", *v);
		//                          0  1   2
		return EXIT_FAILURE;
	}
	char *infile = c > 1 ? v[1] : "-";
	char *outfile = c > 2 ? v[2] : "-";

	int w, h, pd;
	float *x = iio_read_image_float_vec(infile, &w, &h, &pd);
	if (pd != 2) error("2D vector field expected");
	float *y = xmalloc(4*w*h*sizeof*y);
	flowgrad(y, x, w, h);
	iio_save_image_float_vec(outfile, y, w, h, 4);
	free(x);
	return EXIT_SUCCESS;
}
Exemplo n.º 29
0
int main(int c, char *v[])
{
    if (c < 3 || c > 5) {
        fprintf(stderr, "usage:\n\t%s width scale [flow [view]]\n", *v);
        //                          0 1     2      3     4
        return EXIT_FAILURE;
    }
    int width = atoi(v[1]);
    float scale = atof(v[2]);
    char *filename_in = c > 3 ? v[3] : "-";
    char *filename_out = c > 4 ? v[4] : "-";
    int w, h, pd;
    float *f = iio_read_image_float_vec(filename_in, &w, &h, &pd);
    if (pd != 2) fail("need 2D-valued input");
    float *o = xmalloc(width * width * sizeof*o);
    angleplot(o, width, scale, f, w, h);
    iio_save_image_float_vec(filename_out, o, width, width, 1);
    return EXIT_SUCCESS;
}
Exemplo n.º 30
0
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;
}