Using bio-formats and ImageJ2 for plugin

I’m just starting to develop plugins using imagej2 but I’m having trouble getting Bioformats and Imagej2 to work together. I’ve had a look on this forum and some of the posts have got me to the point where I can open an image but I cannot get it to be useable in FIJI. My code is below, Methods 1 and 3 both work in that they open the image but its headless so I can’t use any functions in FIJI. For example I often get users to fine tune the thresholding before the plugin progresses but that can’t happen in headless mode.
Method 2 doesn’t throw any errors but doesn’t open the image either. I’m using Eclipse to develop my plugins so I can see that the image is there in Method 2 I just can’t figure out how to show it.

My guess is that this a context problem but I don’t know how to get the headless version of the image to be recognised by FIJI in my plugin.

Any help greatly appreciated



package net.imagej.imagej;

import net.imagej.Dataset;
import net.imagej.ImageJ;
import net.imagej.ops.OpService;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.type.numeric.RealType;

import ij.ImagePlus;
import loci.plugins.BF;
import loci.common.Region;

import org.scijava.command.Command;
import org.scijava.plugin.Plugin;

@Plugin(type = Command.class, menuPath = “Plugins>Opener”)
public class Opener<T extends RealType> implements Command {

public void run() {


public static void main(final String... args) throws Exception {
	// create the ImageJ application context with all available services
	final ImageJ ij = new ImageJ();
    //Method 1
    //Ask user for file to open
	OpenDialog od = new OpenDialog("Open Image File...");
    String dir = od.getDirectory();
    String name = od.getFileName();
    //Convert path to String variable
    String id = dir + name;

    //Open and display the image
    ImagePlus[] img = BF.openImagePlus(id);
    for (ImagePlus imp : img) {;
    //Method 2
    // ask the user for a file to open
    final File file = ij.ui().chooseFile(null, "Open Image");
    String stringName = file.getAbsolutePath();	
    if (file != null) {
        // load the image
    	ImagePlus[] img2 = BF.openImagePlus(stringName);
        // show the image
  //Method 3
    final File file2 = ij.ui().chooseFile(null, "Open Image");
    String stringName2 = file2.getAbsolutePath();	
    String path = stringName2;
    ImporterOptions options = new ImporterOptions();
    ImagePlus[] imps = BF.openImagePlus(options);


For method 2, does it work if you add a call to showUI first?:

Hello David

Thanks for replying. Unfortunately it still doesn’t work. If I try any sort of interaction with the image from FIJI, for example threshold, I get a null pointer exception in the console. However if I close FIJI the image closes with it so its somehow linked but I can’t figure out how and where.


The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.