[ImageJ-devel] Problems prting plugIn to ImageJ2

Michael Ellis michael.ellis at dsuk.biz
Wed Nov 7 16:57:49 CST 2012

I've just started looking into to porting my existing ImageJ plugins to ImageJ2. I have hit a problem in that calls to functions like setDisplayRange seem not to take effect until my plugin returns.		

The following plugin lets me interactively adjust the image display range when run with ImageJ1 but with ImageJ2 there is no effect to the image until I close the plugIn dialog.

I also note that the ImageJ2 Adjust->Brightness/Contrast (appears new) can update the image interactively, whereas the Adjust->WindowLevel (looks like existing ImageJ1 UI) does not work.

Any help greatly appreciated!

Example code below


package SmartCapture;

import java.awt.AWTEvent;
import ij.IJ;
import ij.ImagePlus;
import ij.gui.DialogListener;
import ij.gui.GenericDialog;
import ij.plugin.filter.ExtendedPlugInFilter;
import ij.plugin.filter.PlugInFilterRunner;
import ij.process.ImageProcessor;

public class Test_IJ2 implements ExtendedPlugInFilter, DialogListener {

	private final static String PLUGIN_NAME = Test_IJ2.class.getSimpleName();

	private static int FLAGS = // bitwise or of the following flags:
	DOES_8G | KEEP_PREVIEW; // When using preview, the preview image can be kept as a result

	ImagePlus imp;
	private double low;
	private double high;

	public int setup(String arg, ImagePlus imp) {

		if (imp == null) {
			IJ.error(PLUGIN_NAME, "No image.\nOpen or create an image first then run "
					+ PLUGIN_NAME);
			return DONE;

		this.imp = imp;

		return FLAGS;

	public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {

		assert (imp != null);
		if (imp == null)
			return DONE;

		GenericDialog gd = new GenericDialog(PLUGIN_NAME + "...");
		gd.addSlider("low", 0, 255, 0);
		gd.addSlider("high", 0, 255, 255);
		gd.addPreviewCheckbox(pfr, " Preview");
		gd.showDialog(); // user input (or reading from macro) happens here
		if (gd.wasCanceled()) // dialog cancelled?
			return DONE;
		return IJ.setupDialog(imp, FLAGS);

	public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {

		low = gd.getNextNumber();
		high = gd.getNextNumber();
		IJ.log(String.format("low=%g high=%g\n", low, high));

		return true;

	public void run(ImageProcessor ip) {
		IJ.log("run called\n");
		imp.setDisplayRange(low, high);

	public void setNPasses(int nPasses) {
		IJ.log(String.format("setNPasses(%d)\n", nPasses));


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20121107/9275374d/attachment.html>

More information about the ImageJ-devel mailing list