/** * Associates a variable name with a source image. The default coordinate * system will be used for this image. * The image will be stored by the builder as a weak reference. * * @param varName variable name * @param sourceImage the source image * @return the instance of this class to allow method chaining */ public JiffleBuilder source(String varName, RenderedImage sourceImage) { return source(varName, sourceImage, null); }
/** * Associates a variable name with a source image. The default coordinate * system will be used for this image. * The image will be stored by the builder as a weak reference. * * @param varName variable name * @param sourceImage the source image * @return the instance of this class to allow method chaining */ public JiffleBuilder source(String varName, RenderedImage sourceImage) { return source(varName, sourceImage, null); }
public static void main(String[] args) throws IOException, JiffleException { String basePath = "/opt/gisData/evo-odas/coverave-view-hetero/multires-s2/S2A_MSIL1C_20170410T103021_N0204_R108_T32UNU_20170410T103020.SAFE/20170410T103021026Z_fullres_CC2.4251_T32UNU_"; // prepare inputs and outputs RenderedImage red = readImage(new File(basePath + "B04.tif")); RenderedImage nir = readImage(new File(basePath + "B08.tif")); TiledImage result = ImageUtilities.createConstantImage(red.getWidth(), red.getHeight(), (float) 0); // build the operation JiffleBuilder builder = new JiffleBuilder(); builder.dest("res", result).source("red", red).source("nir", nir); builder.script("n = nir; r = red; res = (n - r) / (n + r);"); // HERE IS THE NDVI SCRIPT! 5.5 seconds! // builder.script("res = (nir - red) / (nir + red);"); // HERE IS THE NDVI SCRIPT! 7.65 sec! JiffleDirectRuntime runtime = builder.getRuntime(); // actually running the calculation final double pixels = (double) red.getWidth() * (double) red.getHeight(); System.out.println( "Computing " + NumberFormat.getNumberInstance().format(pixels) + " pixels"); long start = System.currentTimeMillis(); runtime.evaluateAll(null); long end = System.currentTimeMillis(); System.out.println("Computation of output took " + (end - start) / 1000.0 + " secs"); System.out.println("Writing output to disk"); ImageIO.write(result, "TIF", new File("/tmp/ndvi.tif")); System.out.println("Writing complete"); }
public RenderedImage buildAndRunScript(File scriptFile, RenderedImage inputImage) throws JiffleException { JiffleBuilder builder = new JiffleBuilder(); builder.script(scriptFile).source("src", inputImage); builder.dest("dest", inputImage.getWidth(), inputImage.getHeight()); builder.run(); return builder.getImage("dest"); } // docs end method
@Test(expected=JiffleRuntimeException.class) public void readOutsideBoundsWithOptionNotSet() throws Exception { System.out.println(" reading outside image bounds with option not set"); String script = "dest = src[$-1, 0];"; RenderedImage srcImg = ImageUtilities.createConstantImage(4, 4, 0); builder.script(script).source("src", srcImg).dest("dest", 4, 4).run(); }
@Test public void nestedCon() throws Exception { String script = "dest = con(src1, con(src1 > src2, 1, null), null);" ; System.out.println(" " + script); final double threshold = IMG_WIDTH * IMG_WIDTH / 2; RenderedImage src1 = createSequenceImage(); RenderedImage src2 = ImageUtilities.createConstantImage(IMG_WIDTH, IMG_WIDTH, threshold); Evaluator e = new Evaluator() { public double eval(double val) { return val > threshold ? 1 : Double.NaN; } }; JiffleBuilder builder = new JiffleBuilder(); builder.script(script).source("src1", src1).source("src2", src2); builder.dest("dest", IMG_WIDTH, IMG_WIDTH); RenderedImage dest = builder.run().getImage("dest"); assertImage(src1, dest, e); }
@Test public void runBasicScript() throws Exception { System.out.println(" basic script with provided dest image"); String script = "dest = con(src1 > 10, src1, null);" ; RenderedImage srcImg1 = createSequenceImage(); WritableRenderedImage destImg = ImageUtilities.createConstantImage(IMG_WIDTH, IMG_WIDTH, 0d); jb.script(script).source("src1", srcImg1).dest("dest", destImg); JiffleDirectRuntime runtime = jb.getRuntime(); runtime.evaluateAll(null); Evaluator e = new Evaluator() { public double eval(double val) { return val > 10 ? val : Double.NaN; } }; assertImage(srcImg1, destImg, e); }
builder.script(script).source("src", srcImg).dest("dest", 4, 4).run();