public static void readLighting(String filename) throws IOException { lighting = new double[4][][]; for (int ly = 0; ly != 2; ++ly) for (int lx = 0; lx != 2; ++lx) lighting[2 * ly + lx] = DataTools.readMatrixDouble(DataTools.openReading(filename + "-" + lx + ly + ".dat")); }
public static void main(String[] args) throws IOException { readParameters(DataTools.DIR + "stitching/" + "10m5m3ml.txt"); readLighting(DataTools.DIR + "light-dist-disk-0"); loadImages(DataTools.DIR + "composites"); // solveFirstOrder(Integer.parseInt(args[0]), Integer.parseInt(args[1]), // Integer.parseInt(args[2])); System.exit(0); ArrayList<double[]>[][] correlations = new ArrayList[NUM_POINTS_Y][NUM_POINTS_X]; for (int y = 0; y != NUM_POINTS_Y; ++y) for (int x = 0; x != NUM_POINTS_X; ++x) correlations[y][x] = new ArrayList<double[]>(); TreeMap<Integer, Double>[] matrix = new TreeMap[NUM_POINTS_X * NUM_POINTS_Y]; for (int i = 0; i != NUM_POINTS_X * NUM_POINTS_Y; ++i) matrix[i] = new TreeMap<Integer, Double>(); // fixed channel final int lx = 0; final int ly = 0; double[] mapped = new double[2]; double[] unmapped = new double[2]; for (int b = 0; b != numImages; ++b) for (int a = 0; a != numImages; ++a) { int u0 = a % su; int v0 = a / su; int u1 = b % su; int v1 = b / su; if (Math.abs(u0 - u1) + Math.abs(v0 - v1) != 1) continue; System.out.println("" + u0 + v0 + "-" + u1 + v1); double xxMin = Double.NEGATIVE_INFINITY; double yyMin = Double.NEGATIVE_INFINITY; double xxMax = Double.POSITIVE_INFINITY; double yyMax = Double.POSITIVE_INFINITY; for (int j = 0; j != 2; ++j) for (int i = 0; i != 2; ++i) { double x = lx + i * (SX - 2); double y = ly + j * (SY - 2); for (int k = 0; k != 2; ++k) { mapPoint(lx, ly, k == 0 ? u0 : u1, k == 0 ? v0 : v1, x, y, mapped); if (i == 0) xxMin = Math.max(xxMin, mapped[0]); else xxMax = Math.min(xxMax, mapped[0]); if (j == 0) yyMin = Math.max(yyMin, mapped[1]); else yyMax = Math.min(yyMax, mapped[1]); } } double x0Min = Double.NEGATIVE_INFINITY; double y0Min = Double.NEGATIVE_INFINITY; double x0Max = Double.POSITIVE_INFINITY; double y0Max = Double.POSITIVE_INFINITY; for (int j = 0; j != 2; ++j) for (int i = 0; i != 2; ++i) { unmapPoint(lx, ly, u0, v0, i == 0 ? xxMin : xxMax, j == 0 ? yyMin : yyMax, unmapped); if (i == 0) x0Min = Math.max(x0Min, unmapped[0]); else x0Max = Math.min(x0Max, unmapped[0]); if (j == 0) y0Min = Math.max(y0Min, unmapped[1]); else y0Max = Math.min(y0Max, unmapped[1]); } for (double y0 = OFFSET_Y; y0 < SY; y0 += SLOPE) { // System.out.println(y0); if (y0 >= y0Min && y0 <= y0Max) for (double x0 = OFFSET_X; x0 < SX; x0 += SLOPE) if (x0 >= x0Min && x0 <= x0Max) { mapPoint(lx, ly, u0, v0, x0, y0, mapped); unmapPoint(lx, ly, u1, v1, mapped, unmapped); double x1 = unmapped[0]; double y1 = unmapped[1]; int p0 = (int) Math.round((x0 - OFFSET_X) / SLOPE); int q0 = (int) Math.round((y0 - OFFSET_Y) / SLOPE); double p1 = (x1 - OFFSET_X) / SLOPE; double q1 = (y1 - OFFSET_Y) / SLOPE; p1 = Math.max(0, Math.min(NUM_POINTS_X - 1, p1)); q1 = Math.max(0, Math.min(NUM_POINTS_Y - 1, q1)); double val0 = sample(lx, ly, u0, v0, x0, y0); double val1 = sample(lx, ly, u1, v1, x1, y1); correlations[q0][p0].add(new double[] {p1, q1, val0, val1}); /*int p1Min = (int) Math.floor(p1); int q1Min = (int) Math.floor(q1); int p1Max = (int) Math.ceil(p1); int q1Max = (int) Math.ceil(q1); double weightX = p1Max - p1; double weightY = q1Max - q1; int[] coefs = new int[5]; double[] weights = new double[5]; coefs[0] = q0 * NUM_POINTS_X + p0; weights[0] = -val1; for (int j = 0; j != 2; ++j) for (int i = 0; i != 2; ++i) { coefs[1 + 2 * j + i] = (j == 0 ? q1Min : q1Max) * NUM_POINTS_X + (i == 0 ? p1Min : p1Max); weights[1 + 2 * j + i] = (i == 0 ? weightX : 1 - weightX) * (j == 0 ? weightY : 1 - weightY) * val0; } for (int j = 0; j != 5; ++j) { TreeMap<Integer, Double> map = matrix[coefs[j]]; for (int i = 0; i != 5; ++i) { if (!map.containsKey(coefs[i])) map.put(coefs[i], 0.); map.put(coefs[i], map.get(coefs[i]) + weights[i] * weights[j]); } }*/ } } } double[][][][] corrArray = new double[NUM_POINTS_Y][NUM_POINTS_X][][]; for (int y = 0; y != NUM_POINTS_Y; ++y) for (int x = 0; x != NUM_POINTS_X; ++x) { corrArray[y][x] = new double[correlations[y][x].size()][]; for (int k = 0; k != corrArray[y][x].length; ++k) corrArray[y][x][k] = correlations[y][x].get(k); } DataOutputStream out = DataTools.openWriting(DataTools.DIR + "stitching/devig-points.dat"); DataTools.writeDoubleArrayArrayMatrix(out, corrArray); out.close(); // out = DataTools.openWriting(DataTools.DIR + "stitching/devig.dat"); // DataTools.writeIntegerDoubleMapArray(out, matrix); // out.close(); }