Example #1
0
int main(int c, char *v[])
{
	char *filename_m = pick_option(&c, &v, "m", "");
	bool old_boundary = pick_option(&c, &v, "o", NULL);
	bool fan_boundary = pick_option(&c, &v, "f", NULL);
	bool Fan_boundary = pick_option(&c, &v, "F", NULL);
	global_parameter_p = atof(pick_option(&c, &v, "p", "NAN"));
	if ((c != 1 && c != 2 && c != 3) || (c>1 && !strcmp(v[1], "-h"))) {
		fprintf(stderr, "usage:\n\t%s [in [out]]\n", *v);
		//                          0  1   2
		return 1;
	}
	char *filename_i = c > 1 ? v[1] : "-";
	char *filename_o = c > 2 ? v[2] : "-";
	if (old_boundary && !fan_boundary)
	{
		fprintf(stderr, "using old boundary\n");
		global_boundary_function = construct_symmetric_boundary_old;
	}
	if (fan_boundary)
	{
		fprintf(stderr, "using fancy boundary\n");
		global_boundary_function = construct_symmetric_boundary_fancy;
	}
	if (Fan_boundary)
	{
		fprintf(stderr, "using Fancy boundary\n");
		global_boundary_function = construct_symmetric_boundary_Fancy;
	}
	if (isfinite(global_parameter_p))
	{
		fprintf(stderr, "using fancier boundary (p=%g)\n",
				global_parameter_p);
		global_boundary_function = construct_symmetric_boundary_fancier;
	}

	int w, h, pd;
	float *x = iio_read_image_float_split(filename_i, &w, &h, &pd);
	float *y = malloc(w*h*pd*sizeof*y);

	ppsmooth_split(y, x, w, h, pd);

	iio_save_image_float_split(filename_o, y, w, h, pd);

	if (*filename_m) {
		for (int i = 0; i < w*h*pd; i++)
			y[i] = x[i] - y[i];
		iio_save_image_float_split(filename_m, y, w, h, pd);
	}

	return 0;
}
Example #2
0
int main(int argc, char **argv)
{

   if (argc < 3) {
      fprintf(stderr, " %s img out area [intensity_threshold (default INF)]\n", argv[0]);
      fprintf(stderr, "   remove connected compotents of img smaller than area\n"
                      "   if intensity difference between two neighboring pixels of img\n"
                      "   is larger than the threshold then the pixels are considered disjoint\n");
      return 1;
   }

   char *img_file = argv[1];
   char *out_file = argv[2];
   int area = atoi(argv[3]);
   float intensity_threshold = argc > 4 ? atof(argv[4]): INFINITY;

   int w,h,nch;

   float *img = iio_read_image_float_split(img_file, &w, &h, &nch);
   float *out = calloc(w*h*nch, sizeof(*out));
   int n_cc = remove_small_cc(w, h, img, out, area, intensity_threshold);
   fprintf(stderr, "remaining components %d\n", n_cc);


	/* write the results */
   iio_save_image_float_split(out_file, out,w,h,nch);
   free(img);
   free(out);
}
Example #3
0
File: homwarp.c Project: mnhrdt/s2p
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;
}
Example #4
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_vec("-", &w, &h, &pixeldim);
	fprintf(stderr, "got a %dx%d image with %d channels\n", w, h, pixeldim);
	iio_save_image_float_split("-", x, w, h, pixeldim);
	free(x);
	return 0;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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 1;
	}
	char *in = c > 1 ? v[1] : "-";
	char *out = c > 2 ? v[2] : "-";

	int w, h, pd;
	float *x = iio_read_image_float_split(in, &w, &h, &pd);
	float *y = xmalloc(w*h*pd*sizeof*y);

	for (int i = 0; i < pd; i++)
		periodic_component(y + w*h*i, x + w*h*i, w, h);

	iio_save_image_float_split(out, y, w, h, pd);

	free(x);
	free(y);
	return 0;
}
Example #8
0
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;
}
Example #9
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;
}
Example #10
0
int main(int c, char *v[])
{
	// process input arguments
	_Bool m = pick_option(&c, &v, "m", NULL);
	if (c < 2 || c > 4) {
		fprintf(stderr, "usage:\n\t%s alpha [dem_in [dem_out]]\n", *v);
		//                          0 1      2       3
		return 1;
	}
	float alpha = atof(v[1]);
	char *filename_in  = c > 2 ? v[2] : "-";
	char *filename_out = c > 3 ? v[3] : "-";

	// read input image
	int w, h, pd;
	float *x = iio_read_image_float_split(filename_in, &w, &h, &pd);
	if (pd != 1) {
		for (int i = 0; i < w*h; i++)
			for (int l = 1; l < pd; l++)
				x[i] += x[i+w*h*l];
		for (int i = 0; i < w*h; i++)
			x[i] /= pd;
	}

	// cast the vertical shadows
	cast_vertical_shadows(x, w, h, alpha);

	// if mask is requested, create a binary mask
	if (m) for (int i = 0; i < w*h; i++)
		x[i] = 255*isnan(x[i]);

	// save the output image
	iio_save_image_float_split(filename_out, x, w, h, 1);

	// cleanup (unnecessary) and exit
	return 0;
}