// evaluate the L2 distance between the image A and the image B translated by d // // A, B: input images // w: width // h: heigth // d: translation vector // // return value: normalized L2 distance // float eval_displacement(float *A, float *B, int w, int h, int d[2]) { long double r = 0; int woff = w/16; int hoff = h/16; int npoints = (w-2*woff)*(h-2*hoff); for (int j = hoff; j < h-hoff; j++) for (int i = woff; i < w-woff; i++) { long double a = getpixel_0(A, w, h, i, j); long double b = getpixel_0(B, w, h, i-d[0], j-d[1]); r += (a - b) * (a - b);///(1.0*npoints); } r = sqrtl(r/npoints); return r; }
// zoom-out by a factor 2 // // in: input image // iw: input image width // ih: input image height // out: output image to be filled-in // ow: output image width (supplied by the user) // oh: output image height (supplied by the user) // static void zoom_out_by_factor_two(float *out, int ow, int oh, float *in, int iw, int ih) { assert(abs(2*ow-iw) < 2); assert(abs(2*oh-ih) < 2); for (int j = 0; j < oh; j++) for (int i = 0; i < ow; i++) { float a[4]; a[0] = getpixel_0(in, iw, ih, 2*i, 2*j); a[1] = getpixel_0(in, iw, ih, 2*i+1, 2*j); a[2] = getpixel_0(in, iw, ih, 2*i, 2*j+1); a[3] = getpixel_0(in, iw, ih, 2*i+1, 2*j+1); out[ow*j + i] = (a[0] + a[1] + a[2] + a[3])/4; } }
// apply a translation to the given image // // in: input image // w: width // h: height // dx: horizontal displacement // dy: vertical displacement // out: output image, to be filled-in void apply_translation(float *out, int dx, int dy, float *in, int w, int h) { for (int j = 0; j < h; j++) for (int i = 0; i < w; i++) { int ii = i - dx; int jj = j - dy; out[j*w+i] = getpixel_0(in, w, h, ii, jj); } }
void cut_n_parts(float *im, int w, int h, int n, float **out) { int w1 = floor(w/n); int h1 = floor(h/n); for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++) for (int k = 0 ; k < w1 ; k++) for (int l = 0 ; l < h1 ; l++) { out[j*n+i][l*w1+k] = getpixel_0(im, w, h, j*w1+k, i*h1+l); } }