Plugin to use Bio-Formats and ImageJ2

Hello,
I want to use Bio-formats within an ImageJ2 plugin but I cannot get the plugin to recognise any formats other than tiff, jpeg etc. Any microscopy proprietary formats can’t be read. I’ve been struggling with what seems to be a basic problem for a while now so I would really appreciate anyone from the Bioformats or Image.net teams giving me a few pointers.

Thanks
David

This is the code I’m using

// create the ImageJ application context with all available services
        final ImageJ ij = new ImageJ();
        ij.launch(args);
        ij.ui().showUI();
        // ask the user for a file to open
        final File file = ij.ui().chooseFile(null, "open");

        if (file != null) {
            // load the dataset
            final Dataset dataset = ij.scifio().datasetIO().open(file.getPath());
            // show the image
            ij.ui().show(dataset);
           
        }

This is the very long dependency list I’m using in my pom file:

<dependencies>
		<dependency>
			<groupId>net.imagej</groupId>
			<artifactId>imagej</artifactId>
		</dependency>
		<dependency>
			<groupId>loci</groupId>
    		<artifactId>loci-common</artifactId>
    		<version>5.0.0-beta1</version>
		</dependency>
		<dependency>
    		<groupId>loci</groupId>
    		<artifactId>loci_plugins</artifactId>
    		<version>5.0.0-beta1</version>
		</dependency>
		<dependency>
    		<groupId>ome</groupId>
    		<artifactId>formats-api</artifactId>
    		<version>6.1.1</version>
		</dependency>
		<dependency>
    		<groupId>loci</groupId>
    		<artifactId>loci-common</artifactId>
    		<version>5.0.0-beta1</version>
		</dependency>		
		<dependency>
    		<groupId>net.imagej</groupId>
    		<artifactId>imagej</artifactId>
    		<version>imagej-2.0.0-rc-69</version>
		</dependency>
		
		<dependency>
			<groupId>net.imglib2</groupId>
			<artifactId>imglib2</artifactId>
		</dependency>
		
		<dependency>
			<groupId>io.scif</groupId>
			<artifactId>scifio</artifactId>
		</dependency>
		<dependency>
			<groupId>io.scif</groupId>
			<artifactId>scifio-ome-xml</artifactId>
		</dependency>
		<dependency>
			<groupId>org.scijava</groupId>
			<artifactId>scijava-common</artifactId>
		</dependency>
		<dependency>
    		<groupId>ome</groupId>
    		<artifactId>bioformats_package</artifactId>
    		<version>6.5.1</version>
		</dependency>
		<dependency>
    		<groupId>ome</groupId>
    		<artifactId>formats-gpl</artifactId>
    		<version>6.1.1</version>
		</dependency>
		<dependency>
    		<groupId>org.openmicroscopy</groupId>
    		<artifactId>ome-common</artifactId>
    		<version>6.0.6</version>
		</dependency>
		<dependency>
    		<groupId>org.openmicroscopy</groupId>
    		<artifactId>ome-xml</artifactId>
    		<version>6.2.2</version>
		</dependency>
	</dependencies>

This is the error:

Exception in thread "main" java.io.IOException: io.scif.img.ImgIOException: io.scif.FormatException: C:\Users\coil\Desktop\Emoke\201209_L2_4_FalconFibers_IF_ChCID488_RbCENPC555_rCal1647_01_02_R3D_D3D_prj.dv: No supported format found.
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:135)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:110)
	at coil.bio.ed.ac.uk.TestOpener.main(TestOpener.java:87)
Caused by: io.scif.img.ImgIOException: io.scif.FormatException: C:\Users\coil\Desktop\Emoke\201209_L2_4_FalconFibers_IF_ChCID488_RbCENPC555_rCal1647_01_02_R3D_D3D_prj.dv: No supported format found.
	at io.scif.img.ImgOpener.createReader(ImgOpener.java:425)
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:125)
	... 2 more
Caused by: io.scif.FormatException: C:\Users\coil\Desktop\Emoke\201209_L2_4_FalconFibers_IF_ChCID488_RbCENPC555_rCal1647_01_02_R3D_D3D_prj.dv: No supported format found.
	at io.scif.services.DefaultFormatService.getFormatList(DefaultFormatService.java:350)
	at io.scif.services.DefaultFormatService.getFormat(DefaultFormatService.java:316)
	at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:88)
	at io.scif.img.ImgOpener.createReader(ImgOpener.java:419)
	... 4 more

The code snippet you posted wont actually be using Bio-Formats to read the images which is why the proprietary formats aren’t being recognised. There are some examples of how to use Bio-Formats from within a macro in bioformats/components/bio-formats-plugins/utils at develop · ome/bioformats · GitHub

Hello David,

Thank you for replying. I’ve looked at the code you recommended and I’m now very confused. The code you suggest appears to be ImageJ 1.x as it opens an ImagePlus but it does it using a massive amount of code. The same thing can be accomplished using the following

static{System.setProperty(“plugins.dir”, “C:/Workspace/IJ/plugins”); //This line for working in Eclipse

IJ.run(“Bio-Formats Importer”);
ImagePlus imp = WindowManager.getCurrentImage();

Does ImageJ2 use Bioformats as the various web pages I’ve been looking at suggest that SCIFIO does use it and that ImageJ2 should open proprietary formats. This post by ctrueden:

states that you should not import bioformats jar files to use it and should use Maven but as you can see by my pom.xml file I’ve put in an extensive list of bioformats related dependencies, none of which worked. I believe ctrueden is one of the developers of ImageJ2 so there seems to be a disconnect between what the imageJ2 developers expect and what the bioformats developers expect when it comes to plugin development.

Can you advise on what is the best course, import jar files or go down the maven route.

Thanks

David

Sorry David, those are ImageJ1 plugins. To use the Bio-Formats readers with SCIFIO it looks like you should use the plugin: GitHub - scifio/scifio-bf-compat: SCIFIO (@scifio/scifio) plug-in allowing the of use Bio-Formats readers.

I would definetly stick to using Maven if you can, the link above provides some extra dependencies for the scifio-bf-compat plugin

1 Like

Have you tried with these dependencies ?

<dependency>
			<groupId>ome</groupId>
			<artifactId>formats-bsd</artifactId>
			<exclusions>
				<exclusion>
					<!-- NB: Exclude problematic uber-JAR that bundles commons-io. -->
					<groupId>ch.systems.cisd</groupId>
					<artifactId>jhdf5</artifactId>
				</exclusion>
				<exclusion>
					<!-- NB: Exclude problematic xalan bundle -->
					<groupId>xalan</groupId>
					<artifactId>xalan</artifactId>
				</exclusion>
				<exclusion>
					<!-- NB: Exclude problematic xml-apis bundle -->
					<groupId>xml-apis</groupId>
					<artifactId>xml-apis</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>ome</groupId>
			<artifactId>formats-gpl</artifactId>
			<exclusions>
				<exclusion>
					<!-- NB: Exclude problematic uber-JAR that bundles commons-io. -->
					<groupId>ch.systems.cisd</groupId>
					<artifactId>jhdf5</artifactId>
				</exclusion>
				<exclusion>
					<!-- NB: Exclude problematic xalan bundle -->
					<groupId>xalan</groupId>
					<artifactId>xalan</artifactId>
				</exclusion>
				<exclusion>
					<!-- NB: Exclude problematic xml-apis bundle -->
					<groupId>xml-apis</groupId>
					<artifactId>xml-apis</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

Not sure the exclusions are necessary.

The required dependencies are explained in the readme of GitHub - scifio/scifio-bf-compat: SCIFIO (@scifio/scifio) plug-in allowing the of use Bio-Formats readers. , as explained by @dgault

Thanks for replying @NicoKiaru and @dgault with your help I’ve managed to get an ImageJ2 plugin to open proprietary formats. Just in case any others are struggling I’ll put my pom.xml dependency list and java code below

Java:

public static void main(final String... args) throws Exception {
        // create the ImageJ application context with all available services
        ImageJ ij = new net.imagej.ImageJ();
        ij.ui().showUI();
    	
    	
        // ask the user for a file to open
        final File file = ij.ui().chooseFile(null, "open");
        String fileName = file.toString(); 
        
        if (fileName != null) {
            
        	// load the dataset
        	Dataset dataset = ij.scifio().datasetIO().open(fileName, null);
 			
        	// show the image
            ij.ui().show(dataset);

            // invoke the plugin
            //	ij.command().run(ExampleFileOpen.class, true);
        }
    }

Pom:

<repositories>
		<repository>
			<id>scijava.public</id>
			<url>https://maven.scijava.org/content/groups/public</url>
		</repository>
		
		<repository>
    		<id>imagej.public</id>
    		<url>http://maven.imagej.net/content/groups/public</url>
  		</repository>
  
	</repositories>

	<dependencyManagement>
  		<dependencies>
    		<!-- NB: Inherit the SCIFIO version management. -->
    		<dependency>
      		<groupId>net.imagej</groupId>
      		<artifactId>pom-imagej</artifactId>
      		<version>5.12.0</version>
    		</dependency>
  		</dependencies>
	</dependencyManagement>

	<dependencies>
		<dependency>
			<groupId>net.imagej</groupId>
			<artifactId>imagej</artifactId>
		</dependency>
		
		<dependency>
    		<groupId>ome</groupId>
    		<artifactId>bioformats_package</artifactId>
    		<version>6.5.1</version> 
		</dependency>
		
		<dependency>
    		<groupId>sc.fiji</groupId>
    		<artifactId>fiji-lib</artifactId>
		</dependency>

		<dependency>
    		<groupId>ome</groupId>
    		<artifactId>scifio</artifactId>
    		<version>5.0.0-rc2</version>
		</dependency>
	
		<dependency>
  			<groupId>io.scif</groupId>
  			<artifactId>scifio</artifactId>
		</dependency>
		
  		<dependency>
  			<groupId>io.scif</groupId>
  			<artifactId>scifio-bf-compat</artifactId>
		</dependency>

		<dependency>
  			<groupId>ome</groupId>
  			<artifactId>formats-bsd</artifactId>
		</dependency>

		<dependency>
  			<groupId>ome</groupId>
  			<artifactId>formats-gpl</artifactId>
		</dependency>
	</dependencies>
1 Like

This is redundant and can be omitted, since maven.imagej.net was migrated to maven.scijava.org a while ago, and the former now redirects to the latter.

Instead of pom-imagej, I recommend pom-scijava, which is the actual “bill of materials” (BOM) for ImageJ and Fiji.
Instead of putting this in <dependencyManagement>, I’d recommend you use pom-scijava directly as a parent POM in your project.

1 Like

Ok, thanks @imagejan I’ll change my pom to reflect your advice as its going to form the starting block for most of my scripts so needs to be correct.
Regards
David

1 Like