// compute residual image for teaser firgure in paper static char *usage ="\n usage: %s in1.png in2.png residout.png\n"; #include "imageLib.h" #include "math.h" #include #define VERBOSE 1 #define ROUND(x) ((x) >= 0? ((int)((x) + .5)) : ((int)((x) - .5))) /* http://www.eecs.harvard.edu/~ayanc/indep_polyc_n/CanonEOS5D-wb1i2e3.htm#b1d5 i_r = 0.936820 R + 0.331565 G + 0.111501 B i_g = -0.076041 R + 0.987069 G + 0.141115 B i_b = -0.062749 R + 0.117385 G + 0.991102 B Red = -1.45e+00 + 1.61e+03 i + -5.72e+03 i^2 + 1.21e+04 i^3 + -1.36e+04 i^4 + 6.05e+03 i^5 Green = 2.66e+00 + 1.96e+03 i + -8.43e+03 i^2 + 2.20e+04 i^3 + -3.23e+04 i^4 + 2.05e+04 i^5 Blue = -1.15e+00 + 2.03e+03 i + -8.49e+03 i^2 + 1.94e+04 i^3 + -2.21e+04 i^4 + 9.78e+03 i^5 */ #define deg 5 int main(int argc, char *argv[]) { double pol[3][deg+1] = /* B, G, R */ {{-1.15e+00, 2.03e+03, -8.49e+03, 1.94e+04, -2.21e+04, 9.78e+03}, { 2.66e+00, 1.96e+03, -8.43e+03, 2.20e+04, -3.23e+04, 2.05e+04}, {-1.45e+00, 1.61e+03, -5.72e+03, 1.21e+04, -1.36e+04, 6.05e+03}}; try { if (argc < 4) throw CError(usage, argv[0]); int argn = 1; char *in1file = argv[argn++]; char *in2file = argv[argn++]; char *outfile = argv[argn++]; CByteImage im1, im2; ReadImageVerb(im1, in1file, VERBOSE); ReadImageVerb(im2, in2file, VERBOSE); CShape sh = im1.Shape(); int w = sh.width, h = sh.height; CByteImage resid(sh); for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ for (int b = 0; b < 3; b++){ double v1 = im1.Pixel(x, y, b); double v2 = im2.Pixel(x, y, b); if (0) { // apply polynomial //v1 /= 255; //v2 /= 255; double s = 0; double v = 1; for (int k = 0; k <= deg; k++) { s += v * pol[b][k]; v *= v1; } v1 = s; } double diff = v1 - v2; //if (diff < 0) diff = -diff; diff *= 1; // scale int idiff = 128 + (int)ROUND(diff); resid.Pixel(x, y, b) = __min(255, __max(0, idiff)); } resid.Pixel(x, y, 3) = 255; // full alpha } } WriteImageVerb(resid, outfile, VERBOSE); } catch (CError &err) { fprintf(stderr, err.message); fprintf(stderr, "\n"); return -1; } return 0; }