Skip to content, Skip to search

Changes

ImageJ1-ImageJ2 cheat sheet

2,663 bytes added, 08:44, 21 November 2018
Fix credit
This page summarizes translation of basic operations of ImageJ1 and ImageJ2 API. Based on the work of Robert Hasse{{Person|Haesleinhuepf}}, Scientific Computing Facility, MPI -CBG Dresden.
{| class="wikitable"
! style="text-align:left;"| ItemTask
! ImageJ1
! ImageJ2
|-
|Starting ImageJ
|<source lang="java">new ij.ImageJ();</source>|<source lang="java">ImageJ ij = new net.imagej.ImageJ();ij.ui().showUI();</source>
|-
|Show images
|<code>imp</code> is an <code>ImagePlus</code> object<source lang="java">imagePlusimp.show()</source>|<source lang="java">ij.ui().show(testImgimp);</source><source lang="java">ImageJFunctions.show(testImgimp);</source><source lang="java">ImageJFunctions.wrap(testImgimp,"Image").show();</source>|-|Retrieve an active image object|<source lang="java">ImagePlus imp = IJ.getImage();</source>|Script parameter (the same for <code>Dataset</code>,<code>ImagePlus</code>, etc.):<source lang="java">#@ Img image</source>In Java code:<source lang="java">@Parameterprivate Img image;</source>Using <code>ImageDisplayService</code>:<source lang="java">Dataset image = ij.imageDisplay().getActiveDataset();</source>|-|Open an image file|<code>IJ.openImage()</code> returns an <code>ImagePlus</code> object without showing.<source lang="testImgjava">ImagePlus imp = IJ.openImage(urlOrFilePath);imp.show();</source><code>IJ.open()</code> automatically shows the image without returning <code>ImagePlus</code>.<source lang="java">IJ.open(urlOrFilePath);ImagePlus imp = IJ.getImage();</source>|Using <code>IOService</code>:<source lang="java">Object image = ij.io().open(urlOrFilePath);</source>Using <code>DatasetIOService</code> (for type safety):<source lang="java">Dataset image = ij.scifio().datasetIO().open(urlOrFilePath);</source>|-|Save an image file|<source lang="java">IJ.saveasTiff(imp, "/path/to/image.tif")</source>|Using <code>IOService</code>:<source lang="java">ij.io().save(dataset, "/path/to/image.tif");</source>Using <code>DatasetIOService</code>:<source lang="java">ij.scifio().datasetIO().save(dataset, "/path/to/image.tif");</source>
|-
|Convert image types
|Convert from ImageJ2 Img object to ImageJ1 <code>ImagePlus</code> object: <source lang="java">ImagePlus imp = ImageJFunctions.wrap(img,"Title");</source>|Convert from ImageJ1 <code>ImagePlus</code> object to ImgLib2 <code>Img</code> object: <source lang="java">Img<T> realImg = ImageJFunctions.wrapReal(imp);</source>
<source lang="java">Img<FloatType> floatImg = ImageJFunctions.convertFloat(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, true, "input", img, "ij", ij);
</source>
|-
|Define plugins
|<source lang="java">
public class ImageNormalizerPlugin implements PluginFilter {
...
}
</source>
In <code>resources/plugins.config</code>:
<source>
Plugins>Filtering, "Normalisation", NormalizerPlugin
</source>
|<source lang="java">
@Plugin(type = Command.class, menuPath = "Plugins>Normalization")
public class ImageNormalizerIJ2Plugin implements Command {
...
}
</source>
|}
https://github.com/mpicbg-scicomp/ij2course-images/blob/master/slides/ij_legacy_cheetsheet.pdf
 
 
[[Category:Tutorials]]
[[Category:Development]]
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
12,249
edits