Difference between revisions of "Scripting toolbox"

(Created page with 'This page is meant to provide small code snippets as a starting point for writing scripts. See also the Scripting comparisons and the dedicated pages for the [[Introduction i...')
 
(Javascript)
Line 17: Line 17:
 
var path = "/path/to/file";
 
var path = "/path/to/file";
 
var imp = IJ.openImage(path);
 
var imp = IJ.openImage(path);
 +
imp.show();
 
</source>
 
</source>
  
Line 27: Line 28:
  
 
* Beanshell
 
* Beanshell
 
  
 
=== Opening an image using Bio-Formats ===
 
=== Opening an image using Bio-Formats ===

Revision as of 07:50, 19 May 2011

This page is meant to provide small code snippets as a starting point for writing scripts. See also the Scripting comparisons and the dedicated pages for the ImageJ Macro language, Javascript, Jython, JRuby, Clojure, and Beanshell.

Opening an image using ImageJ

Macro

path = "/path/to/file";
open(path);

Javascript

importClass(Packages.ij.IJ);

var path = "/path/to/file";
var imp = IJ.openImage(path);
imp.show();


  • Python
  • Ruby
  • Clojure
  • Beanshell

Opening an image using Bio-Formats

Macro

path = "/path/to/file";
run("Bio-Formats Importer", "open=" + path + "autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");

Javascript

importClass(Packages.loci.plugins.BF);

var path = "/path/to/file";
var imps = BF.openImagePlus(path);

or, with more options:

importClass(Packages.loci.plugins.BF);
importClass(Packages.loci.plugins.in.ImporterOptions);
importClass(Packages.loci.common.Region);


var path = "/path/to/file";
var options = new ImporterOptions();
options.setId(path);
options.setAutoscale(true);
options.setCrop(true);
options.setCropRegion(0, new Region(x, y, w. h));
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
var imps = BF.openImagePlus(options);


  • Python
  • Ruby
  • Clojure
  • Beanshell


Opening, processing, and saving a sequence of files in a folder

Macro

dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir);

for (i=0; i<list.length; i++) {
  if (endsWith(list[i], ".tif")) {
    open(dir1 + list[i]);
    // process the image
    saveAs("TIFF", dir2+list[i]);
    close();
  }
}
  • Javascript
  • Python
  • Ruby
  • Clojure
  • Beanshell