/** * Extract the plane at the different positions and concatenate the Dataset * * @param newValue * @return */ private CallbackTask<Void, Void> createSampleImage(File newValue) { return new CallbackTask<Void, Void>() .run( () -> { try { File fileTarget = workflowModel.getMapImages().get(newValue); Dataset datasetTarget = (Dataset) iOService.open(fileTarget.getAbsolutePath()); ImageDisplay imageDisplayTarget = new SilentImageDisplay(); context.inject(imageDisplayTarget); imageDisplayTarget.display(datasetTarget); selectPosition( imageDisplayTarget, workflowModel.getPositionLeft(), workflowModel.getPositionRight(), imageDisplayPaneRight); Dataset datasetSource = (Dataset) iOService.open(newValue.getAbsolutePath()); ImageDisplay imageDisplaySource = new SilentImageDisplay(); context.inject(imageDisplaySource); imageDisplaySource.display(datasetSource); selectPosition( imageDisplaySource, workflowModel.getPositionLeft(), workflowModel.getPositionRight(), imageDisplayPaneLeft); } catch (IOException ex) { Logger.getLogger(ProcessWorkflow.class.getName()).log(Level.SEVERE, null, ex); } }) .submit(loadingScreenService); }
@Test public void testReadmesExample() throws Exception { // extract the example script final File readme = new File("README.md"); final String contents = new String(FileUtils.readFile(readme), "UTF-8"); final String telltale = String.format("```python%n"); final int begin = contents.indexOf(telltale) + telltale.length(); assertTrue(begin > telltale.length()); assertTrue(contents.indexOf(telltale, begin) < 0); final int end = contents.indexOf(String.format("```%n"), begin); assertTrue(end > 0); final String snippet = contents.substring(begin, end); assertTrue(snippet.startsWith("# @ImageJ ij")); final Context context = new Context(); final ScriptService script = context.getService(ScriptService.class); // create mock ImageJ gateway script.addAlias("ImageJ", Mock.class); final ScriptModule module = script.run("op-example.py", snippet, true).get(); assertNotNull(module); module.run(); final Mock ij = context.getService(Mock.class); assertEquals(3, ij.images.size()); assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3); assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3); assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3); }
@Test public void testRot13() throws Exception { final Context context = new Context(ScriptService.class); final ScriptService scriptService = context.getService(ScriptService.class); final ScriptLanguage hello = scriptService.getLanguageByName("Hello"); assertNotNull(hello); final ScriptLanguage rot13 = scriptService.getLanguageByName("Rot13"); assertEquals(hello, rot13); assertEquals("Svool", rot13.getScriptEngine().eval("Hello")); }
@Test public void testScriptModuleValue() throws Exception { final Context context = new Context(ScriptService.class); final ScriptService scriptService = context.getService(ScriptService.class); final ScriptModule module = scriptService .run("test.rot13", ScriptModule.class.getName(), false, (Map<String, Object>) null) .get(); final ScriptModule scriptModule = Rot13Engine.latestModule; assertEquals(module, scriptModule); assertNotNull(scriptModule); final ScriptInfo info = scriptModule.getInfo(); assertEquals(context, info.context()); }
public static void main(final String... args) throws Exception { // make a SciJava application context final Context context = new Context(); // create the script interpreter final ScriptREPL scriptCLI = new ScriptREPL(context); // start the REPL scriptCLI.loop(); // clean up context.dispose(); System.exit(0); }
/** Populates the bindings with the context + services + gateways. */ private void populateBindings(final Bindings bindings) { bindings.put("ctx", context); for (final Service service : context.getServiceIndex().getAll()) { final String name = serviceName(service); bindings.put(name, service); } for (final Gateway gateway : gateways()) { bindings.put(gateway.getShortName(), gateway); } }
@Override public void setItem(WorkflowStep t) { if (configPane == null) { configPane = new ModuleConfigPane(); context.inject(configPane); popover.setContentNode(configPane); // popover.setAnchorLocation(PopupWindow.AnchorLocation.WINDOW_TOP_RIGHT); popover.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP); } this.step = t; configPane.configure(step); titleLabel.setText(step.getModule().getInfo().getTitle()); }
public OpViewer(final Context context) { super("Op Viewer"); context.inject(this); // Load the frame size loadPreferences(); // Top node of the JTree final DefaultMutableTreeNode top = new DefaultMutableTreeNode("Available Ops"); createNodes(top); final JTree tree = new JTree(top); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // Make the JTree scrollable final JScrollPane pane = new JScrollPane( tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setContentPane(pane); try { if (SwingUtilities.isEventDispatchThread()) { pack(); } else { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { pack(); } }); } } catch (final Exception ie) { /* ignore */ } setLocationRelativeTo(null); // center on screen requestFocus(); }
public static Dataset makeDataset(final Context context, final byte[][] data, final String name) { final int w = data.length; final int h = data[0].length; final ArrayImg<ByteType, ByteArray> img = new ArrayImgFactory<ByteType>().createByteInstance(new long[] {w, h}, 1); final ByteType t = new ByteType(img); img.setLinkedType(t); final RandomAccess<ByteType> ra = img.randomAccess(); for (int i = 0; i < w; i++) { ra.setPosition(i, 0); for (int j = 0; j < h; j++) { ra.setPosition(j, 1); ra.get().set(data[i][j]); } } final DatasetService datasetService = context.getService(DatasetService.class); return datasetService.create(new ImgPlus<ByteType>(img, name, new AxisType[] {Axes.X, Axes.Y})); }
public void dummySegmentation() { List<Dataset> predictDataset = new ArrayList<>(imgDatasets.size()); INDArray predict = dummyClassification(); int currIdx = 0; for (int ds = 0; ds < imgDatasets.size(); ds++) { List<List<int[]>> profilesSet = testData.get(ds).getProfiles(); predictDataset.add(imagePlaneService.createEmptyPlaneDataset(imgDatasets.get(ds))); Dataset currDataset = predictDataset.get(ds); RandomAccess<RealType<?>> randomAccess = currDataset.randomAccess(); for (List<int[]> p : profilesSet) { for (int i = 0; i < p.size(); i++) { randomAccess.setPosition(p.get(i)[0], 0); randomAccess.setPosition(p.get(i)[1], 1); double value = predict.getRow(currIdx).getDouble(i); if (value != 0) randomAccess.get().setReal(value); } } Overlay[] overlays = BinaryToOverlay.transform(context, currDataset, true); // List<Overlay> overlayList = Arrays.asList(BinaryToOverlay.transform(context, // currDataset, true)); overlayStatService.setRandomColor(Arrays.asList(overlays)); ImageDisplay display = new DefaultImageDisplay(); context.inject(display); display.display(currDataset); for (Overlay o : overlays) { display.display(o); } uis.show(display); } }
public ScriptREPL(final Context context, final OutputStream out) { context.inject(this); this.out = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); }
@Override public void setContext(final Context context) { context.inject(this); }