Writing Custom Import Code
Custom import code can be written using Wayne Rasband's ImageJ 1.29.
The custom class must:
- Have a public constructor that takes java.lang.String as its only argument. This string is the
path name of the file to be imported.
- Have exactly one public method that takes no arguments and returns an ImageJ object of type ij.ImagePlus. This object
should be 8 or 16 bit (i.e., invoking its 'getType()' method should return ij.ImagePlus.GRAY8 or
ij.ImagePlus.GRAY16).
It is possible to write a custom class that serves as an ImageJ plug-in and as a MultiTracer
custom class by using the following general strategy:
- Declare the class as extending ij.plugin.Plugin as required for all ImageJ plugins
- Provide two public constructors, one of which has no arguments (for use with ImageJ) and the
other of which has java.lang.String as its only argument (for use with MultiTracer)
- Set a flag in one of both constructors to indicate which constructor was invoked
- Declare an instance of ij.ImagePlus that is global to the class instance
- Have the public constructor that uses java.lang.String as its argument invoke the
public method "run(java.lang.String)" using the same java.lang.String argument
- Within the run(java.lang.String) method, create an object of type ij.ImagePlus. If the
class was invoked with no arguments (indicating use as an ImageJ plugin), invoke the show() method
to display the loaded image. If the class was invoked with a java.lang.String argument (indicating
use as a MultiTracer custom class), set the global ij.ImagePlus to be the created ij.ImagePlus
object.
- Set the global ij.ImagePlus object to null initially when run(java.lang.String) is invoked
- Add a public method that takes no arguments and that returns the global ij.ImagePlus object
The following is a skeleton to illustrate a class that serves as an ImageJ import plugin and as a
MultiTracer custom import class
// Do not declare a package--doing so breaks ImageJ and MultiTracer
public class ExampleImporter implements ij.plugin.Plugin {
private ij.ImagePlus globalImagePlus=null;
private boolean isPlugIn=false;
public ExampleImporter(){
isPlugIn=true;
}
public ExampleImporter(java.lang.String arg){
run(arg);
}
public void run(java.lang.String arg){
globalimagePlus=null; // Important if class is reused by MultiTracer to load another image
// Add code here to load data and create an ij.ImagePlus object called localImagePlus
if(isPlugIn) localImagePlus.show(); // Causes image to be displayed in ImageJ
else globalImagePlus=localImagePlus;
}
public ij.ImagePlus getImagePlus(){
return globalImagePlus; // if null, MultiTracer will report an import failure to the user
}
}
©2001-2003 Roger P. Woods, M.D.
Modified: April 3, 2003