Loci.plugin.in.colorizer when importing through BioFormats

Hi all,

I’m trying to convert some of my working scripts to Groovy in order to practice and get used to it and I’m having a weird result.

I have this function which is working in Python and I’m now using in Groovy.

/**
 * Import the files using BioFormats
 * @param individual_file       Path to the file to open
 * @return imps                 ImagePlus of the opened file
 */
def BFImport(String individual_file)
{
    options = new ImporterOptions()
    options.setId(individual_file)
    options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE)
    imps = BF.openImagePlus(options)
    return imps
}

The rest of the script is working in Python but this call

imps = BFImport(file)
println imps.getClass()

imp = imps[0]
imp.show()
println imp.getClass()

is giving me a loci.plugin.in.colorizer instead of an ImagePlus. Am I missing something ?

Thanks a lot for your help !

I’m not sure what the problem is. I cannot reproduce it here.

Here is my implementation

import ij.IJ
import loci.plugins.in.ImporterOptions
import loci.plugins.BF

/**
 * Import the files using BioFormats
 * @param individual_file       Path to the file to open
 * @return imps                 ImagePlus of the opened file
 **/
def BFImport(String individual_file)
{
    options = new ImporterOptions()
    options.setId(individual_file)
    options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE)
    imps = BF.openImagePlus(options)
    return imps
}

IJ.run("Close All")

imps = BFImport("/my/path/to/tiffimage.tif")
println imps.getClass()

imp = imps[0]
imp.show()
println imp.getClass()

and the output is:

class [Lij.ImagePlus;
class ij.ImagePlus

I tried these on some tif images I have and I got red LUTS but otherwise were OK. Can you upload a small test image that fails? I’d be happy to run it on my MacBook.

Best regards,
John Minter

Hi @lguerard, this is a rather confusing one to explain. What you are probably seeing is:

class loci.plugins.in.Colorizer$1

The $1 means that its an inner class of Colorizer. What is actually happening is that when you open a composite image the Colorizer class is called and returns a list of CompositeImage. The CompositeImage extends ImagePlus and this is (more or less) the class you are seeing. Why it appears so strange is because Colorizer is overriding some of the methods in CompositeImage (see https://github.com/openmicroscopy/bioformats/blob/develop/components/bio-formats-plugins/src/loci/plugins/in/Colorizer.java#L166). This is why it appears as though it is an inner class of Colorizer rather than a CompositeImage .

But in reality you can treat it just like an ImagePlus.

1 Like

Hi @dgault,

Sorry for the late answer.

I see, this makes more sense, thanks ! :slight_smile:

Another question about this, in python, I was using this function and then I had a loop

for imp in imps

which doesn’t work in groovy. Why does it have a different behaviour ?

And what’s the difference between

class [Lij.ImagePlus

and

class ij.ImagePlus

?

Thanks again !

If you want to loop through them the nicest groovy way of doing this is

imps.each{ imp ->
    ...
}
1 Like