Difference between revisions of "ImageJ1-ImageJ2 cheat sheet"

Line 22: Line 22:
 
<source lang="java">Img<FloatType> floatImg = ImageJFunctions.convertFloat(imp);</source>
 
<source lang="java">Img<FloatType> floatImg = ImageJFunctions.convertFloat(imp);</source>
 
<source lang="java">Img<FloatType> realImg2 = ImageJFunctions.wrap(imp);</source>
 
<source lang="java">Img<FloatType> realImg2 = ImageJFunctions.wrap(imp);</source>
 +
|-
 +
|Show regions
 +
|<source lang="java">imagePlus.setRoi(roi)</source>
 +
|<source lang="java">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);</source>
 +
|-
 +
|Run plugins
 +
|<source lang="java">IJ.run(imagePlus,"Normalisation","");</source>
 +
|<source lang="java">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></source>
 +
|-
 +
|Define plugins
 +
|<source lang="java">public class ImageNormalizerPlugin implements PluginFilter {
 +
resources/plugins.config:
 +
Pluins>Filtering, "Normalisation", NormalizerPlugin
 +
}</source>
 +
|<source lang="java">@Plugin(type = Command.class, menuPath = "Plugins>Normalization")
 +
public class ImageNormalizerIJ2Plugin implements Command {</source>
 
|}
 
|}
  

Revision as of 17:50, 30 June 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.

Item ImageJ1 ImageJ2
Starting ImageJ
ij.ImageJ
ImageJ ij = new net.imagej.ImageJ();
ij.ui().showUI();
Show images
imagePlus.show()
ij.ui().show(testImg);
ImageJFunctions.show(testImg);
ImageJFunctions.wrap(testImg,"testImg").show();
Convert image types
ImagePlus imp = ImageJFunctions.wrap(img,"Title");
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