public static BufferedImage getStitchImageDevig( final int stitch, final int scale, final int color) throws IOException { File file = new File( String.format( "%s/stitch-image-devig/%d/%d/%d.png", Cache.CACHE.getAbsolutePath(), stitch, scale, color)); if (file.exists()) return ImageIO.read(file); StitchStackProperties stack = getStitchStackProperties(); BufferedImage[] images = new BufferedImage[stack.getImageSetProperties(stitch).getNumImages()]; for (int image = 0; image != images.length; ++image) images[image] = MetalTools.toImage(getColorComponentDevig(stitch, image, color), 128); BufferedImage result = Sharpness.render( scale, stack, stitch, color + color / 2, images, color == 1 ? 1 : 0.5, Sharpness.computeEdges(stitch, color, 0, true)); file.getParentFile().mkdirs(); ImageIO.write(result, "png", file); return result; }
public static double[][] getImageComponent(final int stitch, final int image, final int channel) throws IOException { String path = String.format("%s/images/%d/%d/%d", Cache.CACHE.getAbsolutePath(), stitch, image, channel); if (!new File(path).exists()) initImageComponents(stitch, channel); return Streams.readObject(path); }
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]); } }
public static BufferedImage getGreenImage(final int stitch, final int image) throws IOException { File file = new File(Cache.CACHE.getCanonicalPath() + "/images-green/" + stitch + "/" + image + ".png"); if (file.exists()) return ImageIO.read(file); BufferedImage result = MetalTools.toImage(getInterpolatedImage(stitch, image), 128); Tools.ensurePath(file.getAbsolutePath()); ImageIO.write(result, "png", file); return result; }
public static BufferedImage getStitchImageDevigColorized(final int stitch, final int scale) throws IOException { File file = new File( String.format( "%s/stitch-image-devig-color/%d/%d.png", Cache.CACHE.getAbsolutePath(), stitch, scale)); if (file.exists()) return ImageIO.read(file); BufferedImage[] images = new BufferedImage[3]; for (int color = 0; color != images.length; ++color) images[color] = getStitchImageDevig(stitch, scale, color); BufferedImage result = combineColors(images); file.getParentFile().mkdirs(); ImageIO.write(result, "png", file); return result; }