public static double[][] getFixedRawComponent( final int stitch, final int image, final int channel) throws IOException { double[][] result = getRawComponent(stitch, image, channel); fixDeadPixels(result, getDeadPixelsInComponent(channel)); return ImageOpsDouble.mul( (result.length * result[0].length) / ImageOpsDouble.sum(result), result); }
private static void initImageComponents(final int stitch, final int channel) throws IOException { StitchStackProperties stack = getStitchStackProperties(); Map[] maps = map.Utils.getMapsFromStack(stack, stitch, channel, true); double[][] lighting = Streams.readObject(DataTools.DIR + "light-dist-20"); double[] secondOrderLighting = new double[maps.length]; double[] directionalLighting = new double[2]; readSecondOrderLighting( DataTools.DIR + "devig-second-order-n" + StitchInfo.SUFFICES[stitch] + ".txt", secondOrderLighting, directionalLighting); int sx = stack.getImageSetProperties(0).getSize().getSx(); int sy = stack.getImageSetProperties(0).getSize().getSy(); double[] coords = new double[2]; double sum = 0; double[][][] components = new double[maps.length][][]; for (int image = 0; image != components.length; ++image) { components[image] = getRawComponent(stitch, image, channel); for (int b = 0; b != sy / 2; ++b) for (int a = 0; a != sx / 2; ++a) { int x = 2 * a + channel % 2; int y = 2 * b + channel / 2; coords[0] = x; coords[1] = y; maps[image].map(coords, coords); double directionalLight = 0; for (int i = 0; i != 2; ++i) directionalLight += directionalLighting[i] * coords[i]; double light = lighting[y][x] * secondOrderLighting[image] * Math.exp(0.5 * directionalLight); components[image][b][a] /= light; } fixDeadPixels(components[image], getDeadPixelsInComponent(channel)); sum += ImageOpsDouble.mean(components[image]); } sum /= components.length; for (int image = 0; image != components.length; ++image) { components[image] = ImageOpsDouble.mul(1 / sum, components[image]); String path = String.format( "%s/images/%d/%d/%d", Cache.CACHE.getAbsolutePath(), stitch, image, channel); new File(path).getParentFile().mkdirs(); Streams.writeObject(path, components[image]); } }