2

If I use Fiji application to open an image, then the image is displayed in a window where I can use + and - keys to zoom in and out, also I can hold down the space bar and drag the zoomed image with mouse to scroll through it.

I want to implement the same features in a java application using ImageJ API. If I use the following code (taken from here) to open an image, then the image is displayed in the same type of window as in Fiji case, but zoom and drag to scroll features are not active in the window.

Opener opener = new Opener();  
ImagePlus imp = opener.openImage("/path/to/image.tif");  
imp.show();

Could somebody suggest how to get the two features active? To me they look like standard features that everybody uses, so I expect that their activation could be easily available through the ImageJ API. However I found no hints in the API specs.

As far as I understand, the call imp.show(); in the code above is equivalent to the following:

ImageWindow imageWindow = new ImageWindow(imp);
imageWindow.setVisible(true);

If so, there should be some methods of this ImageWindow class that would assure activation of zoom and of drag to scroll. Does anyone have a clue?

Or, maybe, could someone share a direct link to Fiji source code where these exact features are implemented? Is it supposed to be here? If yes, then where exactly?

croset3
  • 73
  • 8

2 Answers2

1

Perhaps you should be looking more at the ImageJ source code. I'm assuming this is for ImageJ1. My guess is that the keybindings are set when the main gui is loaded in the ImageJ class

Having downloaded the imagej1 source code and doing a grep for zoom I found

./IJ_Props.txt:zoom01="In [+]",ij.plugin.Zoom("in")
./IJ_Props.txt:zoom02="Out [-]",ij.plugin.Zoom("out")
./IJ_Props.txt:zoom03="Original Scale[4]",ij.plugin.Zoom("orig")
./IJ_Props.txt:zoom04="View 100%[5]",ij.plugin.Zoom("100%")
./IJ_Props.txt:zoom05="To Selection",ij.plugin.Zoom("to")
./IJ_Props.txt:zoom06="Scale to Fit",ij.plugin.Zoom("scale")
./IJ_Props.txt:zoom07="Set... ",ij.plugin.Zoom("set")

Try launching the main GUI with the ImageJ class. Alternatively lookat how the key listener is set up in that class.

There are multiple places in the code of ImageJ that are of interest to you. Line 388 for example is the beginning of the KeyPressed method.

After those actions the doCommand methdod calls the respective plugin.

Codey McCodeface
  • 2,988
  • 6
  • 30
  • 55
0

I resolved it. As I expected, there exists a simple way to activate zoom and drag to scroll features of ImageJ in a Java program.

As I see now, most of the features of ImageJ are implemented as plugins under ij.plugin.*.

To activate a desired ImageJ feature in your Java program you need (1) to find the plugin that corresponds to the feature inside ij.plugin.* package, (2) to call the plugin in your code, and (3) to put IJ_Props.txt file taken from the standard ImageJ distribution to the directory where you run your java .jar executable (it appears that IJ_Props.txt file contains settings used by many of the available ImageJ plugins).

So, in our case we need to activate ij.plugin.Zoom plugin in our java code:

//Launch ImageJ in NO_SHOW mode: Run embedded and invisible in another application.
ImageJ imageJApplication = new ImageJ(2);

Opener opener = new Opener();  
String imageFilePath = "path/to/your/image.png";
ImagePlus imp = opener.openImage(imageFilePath);
imp.show();
IJ.runPlugIn("ij.plugin.Zoom", null);

When executing this code we get ij.plugin.Zoom plugin activated and both of the desired features (zoom and drag to scroll) will be functional in the window where our image is displayed. We also get the traditional ImageJ thumbnail view of the displayed image area in the upper left corner of the window.

croset3
  • 73
  • 8