Difference between revisions of "ImageJ1-ImageJ2 cheat sheet"

Line 16: Line 16:
 
<source lang="java">ImageJFunctions.show(testImg);</source>
 
<source lang="java">ImageJFunctions.show(testImg);</source>
 
<source lang="java">ImageJFunctions.wrap(testImg,"testImg").show();</source>
 
<source lang="java">ImageJFunctions.wrap(testImg,"testImg").show();</source>
 +
|-
 +
|Retrieve an object from an open image
 +
|<source lang="java">ImagePlus imp = IJ.getImage();</source>
 +
|<source lang="java"></source>
 
|-
 
|-
 
|Open an image file
 
|Open an image file
Line 25: Line 29:
 
<source lang="java">IJ.open("/path/to/image.tif");
 
<source lang="java">IJ.open("/path/to/image.tif");
 
ImagePlus imp = IJ.getImage()</source>
 
ImagePlus imp = IJ.getImage()</source>
<source lang="java">IJ.open("http://www.example.org/path/to/image.tif");ImagePlus imp = IJ.getImage()</source>
+
<source lang="java">IJ.open("http://www.example.org/path/to/image.tif");
 +
ImagePlus imp = IJ.getImage()</source>
 
|<source lang="java"></source>
 
|<source lang="java"></source>
 
|-
 
|-

Revision as of 01:06, 9 October 2018

This page summarizes translation of basic operations of ImageJ1 and ImageJ2 API. Based on the work of Robert Hasse, Scientific Computing Facility, MPI CBG Dresden.

Task ImageJ1 ImageJ2
Starting ImageJ
ij.ImageJ
ImageJ ij = new net.imagej.ImageJ();
ij.ui().showUI();
Show images imp is an ImagePlus object
imp.show()
ij.ui().show(testImg);
ImageJFunctions.show(testImg);
ImageJFunctions.wrap(testImg,"testImg").show();
Retrieve an object from an open image
ImagePlus imp = IJ.getImage();

Open an image file IJ.openImage() returns an ImagePlus object without showing.
ImagePlus imp = IJ.openImage("/path/to/image.tif");
imp.show();
ImagePlus imp = IJ.openImage("http://www.example.org/path/to/image.tif");  
imp.show();

IJ.open() automatically shows the image without returning ImagePlus.

IJ.open("/path/to/image.tif");
ImagePlus imp = IJ.getImage()
IJ.open("http://www.example.org/path/to/image.tif");
ImagePlus imp = IJ.getImage()

Save an image file
IJ.saveasTiff(imp, "/path/to/image.tif")

Convert image types Convert from ImageJ2 Img object to ImageJ1 ImagePlus object:
ImagePlus imp = ImageJFunctions.wrap(img,"Title");
Convert from ImageJ1 ImagePlus object to ImageJ Img object:
Img<T> realImg = ImageJFunctions.wrapReal(imp);
Img<FloatType> floatImg = ImageJFunctions.convertFloat(imp);
Img<FloatType> realImg2 = ImageJFunctions.wrap(imp);
Show regions
imagePlus.setRoi(roi)
Img<BitType> mask; // = ...
ImagePlus maskImp =ImageJFunctions.wrap(mask, "mask");
// threshold the mask to get an ROI
ImageProcessor imageProcessor = maskImp.getProcessor();
imageProcessor.setThreshold(128,128,ImageProcessor NO_LUT_UPDATE);
Roi roi = new ThresholdToSelection().convert(imageProcessor);
imagePlus.setRoi(roi);
Run plugins
IJ.run(imagePlus,"Normalisation","");
ij.command().run(ImageNormalizerIJ2Plugin.class,false, new Object[]{"input", img, "ij", ij});
IJ.run(imagePlus,"Normalisation (IJ2)", "");
// don't forget the IJ legacy dependency
<dependency>
  <groupId>net.imagej</groupId>
  <artifactId>imagej-legacy</artifactId>
</dependency>
Define plugins
public class ImageNormalizerPlugin implements PluginFilter {
resources/plugins.config:
Pluins>Filtering, "Normalisation", NormalizerPlugin
}
@Plugin(type = Command.class, menuPath = "Plugins>Normalization")
public class ImageNormalizerIJ2Plugin implements Command {


See also

https://github.com/mpicbg-scicomp/ij2course-images/blob/master/slides/ij_legacy_cheetsheet.pdf