/** * Runs the script. Equivalent to calling * {@code builder.getRuntime().evaluateAll(null)}. * * @return the instance of this class to allow method chaining * * @throws JiffleException if the script has not been set yet or if * compilation errors occur */ public JiffleBuilder run() throws JiffleException { getRuntime().evaluateAll(null); return this; }
/** * Runs the script. Equivalent to calling * {@code builder.getRuntime().evaluateAll(null)}. * * @return the instance of this class to allow method chaining * * @throws JiffleException if the script has not been set yet or if * compilation errors occur */ public JiffleBuilder run() throws JiffleException { getRuntime().evaluateAll(null); return this; }
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"); }
/** * Compiles and runs the "ripple" script using {@link JiffleBuilder}. * @param args ignored * @throws Exception if there are errors compiling the script. */ public static void main(String[] args) throws Exception { JiffleBuilderDemo me = new JiffleBuilderDemo(); File f = JiffleDemoHelper.getScriptFile(args, ImageChoice.RIPPLES); String script = JiffleDemoHelper.readScriptFile(f); JiffleBuilder jb = new JiffleBuilder(); jb.script(script).dest("result", WIDTH, HEIGHT).getRuntime().evaluateAll(null); ImageFrame frame = new ImageFrame(jb.getImage("result"), "Jiffle image demo"); frame.setVisible(true); } }
@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); }
@Test public void builderCreatesDestImage() throws Exception { System.out.println(" builder creating dest image"); String script = "init { n = 0; } dest = n++ ;" ; jb.dest("dest", IMG_WIDTH, IMG_WIDTH).script(script).getRuntime().evaluateAll(null); RenderedImage img = jb.getImage("dest"); assertNotNull(img); RandomIter iter = RandomIterFactory.create(img, null); int k = 0; for (int y = 0; y < IMG_WIDTH; y++) { for (int x = 0; x < IMG_WIDTH; x++) { assertEquals(k, iter.getSample(x, y, 0)); k++ ; } } }