private void writeTiles(
     File outputLevelDir,
     String tileFormat,
     PlanarImage image,
     int tileWidth,
     int tileHeight,
     int numXTiles,
     int numYTiles) {
   for (int tileY = 0; tileY < numYTiles; tileY++) {
     for (int tileX = 0; tileX < numXTiles; tileX++) {
       final int x = tileX * tileWidth;
       final int y = tileY * tileHeight;
       Rectangle region = new Rectangle(x, y, tileWidth, tileHeight);
       BufferedImage bufferedImage = image.getAsBufferedImage(region, null);
       final String baseName = tileX + "-" + tileY + "." + tileFormat;
       FileStoreDescriptor.create(
           bufferedImage,
           new File(outputLevelDir, baseName).getPath(),
           tileFormat,
           null,
           false,
           null);
     }
   }
 }
示例#2
0
 public static void storeTiledTiff(RenderedImage image, String filePath) {
   final TIFFEncodeParam encodeParam = new TIFFEncodeParam();
   encodeParam.setTileSize(image.getTileWidth(), image.getTileHeight());
   encodeParam.setWriteTiled(true);
   encodeParam.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
   System.out.println("Storing tiled TIFF image to " + filePath + "...");
   FileStoreDescriptor.create(image, filePath, "TIFF", encodeParam, false, null);
 }
示例#3
0
  public static void main(String[] args) {
    String sourceFile = args[0];
    int m = Integer.parseInt(args[1]);

    String format = sourceFile.substring(1 + sourceFile.lastIndexOf('.'));
    String targetBase = sourceFile.substring(0, sourceFile.lastIndexOf('.'));
    String targetFile0 = targetBase + "_" + m + "_0." + format;
    String targetFile1 = targetBase + "_" + m + "_1." + format;
    String targetFile2 = targetBase + "_" + m + "_2." + format;

    KernelJAI gaussKernel = createGaussianKernel(m);
    dumpKernelData("Gaussian", gaussKernel);
    KernelJAI distKernel = createDistancesKernel(m);
    dumpKernelData("Distances", distKernel);

    RenderedOp source = FileLoadDescriptor.create(sourceFile, null, true, null);
    source = BandSelectDescriptor.create(source, new int[1], null);
    System.out.println("Writing " + targetFile0);
    FileStoreDescriptor.create(source, targetFile0, format, null, false, null);

    long t1 = System.currentTimeMillis();
    System.out.println("Computing " + targetFile1);
    BorderExtender borderExtender = BorderExtender.createInstance(BorderExtender.BORDER_COPY);
    RenderedOp target1 =
        ConvolveDescriptor.create(
            source, gaussKernel, new RenderingHints(JAI.KEY_BORDER_EXTENDER, borderExtender));
    RenderedOp mask = ClampDescriptor.create(source, new double[] {0}, new double[] {1}, null);
    mask = MultiplyConstDescriptor.create(mask, new double[] {255}, null);
    mask = NotDescriptor.create(mask, null);
    mask = ClampDescriptor.create(mask, new double[] {0}, new double[] {1}, null);
    target1 = MultiplyDescriptor.create(target1, mask, null);
    target1 = AddDescriptor.create(target1, source, null);
    System.out.println("Writing " + targetFile1);
    FileStoreDescriptor.create(target1, targetFile1, format, null, false, null);
    System.out.println("Done in " + (System.currentTimeMillis() - t1) + " ms");

    long t2 = System.currentTimeMillis();
    System.out.println("Computing " + targetFile2);
    BufferedImage target2 = convolveICOL(source, gaussKernel, distKernel);
    System.out.println("Writing " + targetFile2);
    FileStoreDescriptor.create(target2, targetFile2, format, null, false, null);
    System.out.println("Done in " + (System.currentTimeMillis() - t2) + " ms");
  }