int shomwarp(float *X, int W, int H, double M[9], float *x, int w, int h, int o) { // if low order-interpolation, evaluate right away if (o == 0 || o == 1 || o == 2 || o == -3) return homwarp(X, W, H, M, x, w, h, o); // otherwise, pre-filtering is required bool r = prepare_spline(x, w, h, 1, o); if (!r) return 2; // warp the points for (int j = 0; j < H; j++) for (int i = 0; i < W; i++) { double p[2] = {i, j}; apply_homography(p, M, p); p[0] += 0.5; // solve a mis-alignement convention p[1] += 0.5; float *out = X + (j*W + i); evaluate_spline_at(out, x, w, h, 1, o, p[0], p[1]); } 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; }