Posted in
Extensibility is ImageJ's greatest strength. We want to make it easier to extend ImageJ in even more powerful ways.
Dependency injection is a nice mechanism for discovering and loading all objects matching certain criteria. For example, it can be used to find all plugins available on the Java classpath, without knowing in advance what they are or where they are located. We are currently using SezPoz for dependency injection, which allows Java annotations to be discovered via service lookups.
Here is an example plugin using our parameterized approach:
import imagej.data.Dataset;
import imagej.data.DatasetFactory;
import net.imglib2.img.Axes;
import net.imglib2.img.Axis;
import net.imglib2.type.numeric.integer.UnsignedByteType;
/** A simple demonstration plugin, which generates a gradient image. */
@Plugin(menuPath = "File>New>Gradient Image")
public class GradientImage implements ImageJPlugin {
@Parameter(min = "1")
private int width = 512;
@Parameter(min = "1")
private int height = 512;
@Parameter(output = true)
private Dataset dataset;
@Override
public void run() {
byte[] data = new byte[width * height];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int index = y * width + x;
data[index] = (byte) (x + y);
}
}
final String name = "Gradient Image";
final long[] dims = { width, height };
final Axis[] axes = { Axes.X, Axes.Y };
dataset = DatasetFactory.create(new UnsignedByteType(), dims, name, axes);
dataset.setPlane(0, data);
}
}
More details and examples to follow later.
