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 != 3) { fprintf(stderr, "usage:\n\t%s img.tiff hist.tiff\n", *v); // 0 1 2 return 1; } char *filename_in = c > 1 ? v[1] : "-"; char *filename_out = c > 2 ? v[2] : "-"; int w, h, pd; float *x = iio_read_image_float_split(filename_in, &w, &h, &pd); int nbins = 256; double H[pd*nbins]; for (int i = 0; i < pd*nbins; i++) H[i] = 0; for (int l = 0; l < pd; l++) for (int i = 0; i < w*h; i++) { float v = x[w*h*l + i]; if (!isfinite(v)) continue; int idx = floor(v); if (idx < 0) idx = 0; if (idx >= nbins) idx = nbins - 1; H[l*nbins+idx] += 1; } iio_save_image_double(filename_out, H, nbins, pd); return 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); }
// 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; }
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; }
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; }
int main(int c, char *v[]) { if (c != 1 && c != 2 && c != 3) return fprintf(stderr, "usage:\n\t%s [in [out]]\n", *v); // 0 1 2 char *filename_in = c > 1 ? v[1] : "-"; char *filename_out = c > 2 ? v[2] : "-"; int w, h, pd; float *x = iio_read_image_float_split(filename_in, &w, &h, &pd); float *y = malloc(w*h*pd*sizeof*y); mima_separable(y, x, w, h, pd); iio_write_image_float_split(filename_out, y, w, h, pd); free(x); free(y); return 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; }
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 != 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; }
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; }
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; }