Fiji - Script Editor - Batch button

Dear All, Dear @imagejan,

I’m facing a weird problem when running the groovy script below from the Fiji script editor with Run vs Batch :

#@ ImagePlus imp

rt = ResultsTable.getResultsTable()
if (rt==null) ResultsTable.ResultsTable()

imp_cal = imp.getCalibration()
println imp_cal.getUnit()	

distance = 10;
rt.incrementCounter()
rt.addValue("A value", distance)
rt.addValue("A scaled value ("+imp_cal.getUnit()+")", distance * imp_cal.pixelWidth)
rt.show()

import ij.* 
import ij.measure.ResultsTable

If I open an image, and press Run, I get what I expect eg a table with 2 columns with a raw and a scaled value.
image

If I use the Batch button, select multiple images, it seems it can’t get the calibration unit info , but still get the pixelWidth
image

It seems that in Batch the unit information is lost…

Best,

Romain

3 Likes

Hmm, interesting. I admit I don’t have much experience with using the Batch button, but I am curious about the type of file you are opening and whether it needs something to read the metadata like BioFormats? Does Batch intelligently open the images with the correct reader?

Honestly not sure how it works, just throwing that out there :slight_smile: I do all my batch processing so far through the scripts and batchmode in IJ1, so I am curious to know.

The images are *.ome.tif , please find an exampleImage.ome.tif (2.8 MB)

Opening it with bio-formats, I got unit as “micron”

Opening it with File>Open… , I got unit as “µm”

Adding imp.show(), to see the image, shows a virtual image ("(V)" in the window name).
I tried to use File>Import> Tiff virtual stack… and I got unit as “µm”

Best,

R

1 Like

Hi @romainGuiet, and apologies for the delayed reply,

The SciJava batch-processor uses DatasetIOService from SCIFIO/ImageJ2 to open images, and this seems to be an issue specific to the #scifio library.

I can reproduce the missing unit by opening your sample file via File › Import › Image…, which uses #scifio (the methods you tried were the ImageJ1 TIFFReader and #bio-formats).

To find out whether the unit gets lost a) while opening the file with scifio, or b) when converting from Dataset to ImagePlus (i.e. from an IJ2 object to an IJ1 object to display it in the legacy UI), I tried the following Groovy script:

#@ DatasetIOService io
#@ File inputFile

import net.imagej.axis.Axes

dataset = io.open(inputFile.getPath())

println dataset.axis(Axes.X).get().unit()

… and indeed, this gives:

null

… so it is a #scifio issue.

More importantly, the issue seems to be specific to .ome.tif files, since when I resave your image as plain TIFF and then re-open it with my script, it prints:

\u00B5m

… which arguably is also not entirely correct (it’s the Unicode representation of µm but should in fact be µm when printed), but at least we got some unit preserved.

Maybe @hinerm has some insight where in #scifio and why this happens. I’ll open an issue, and maybe – if I find the cause – even a pull request…

4 Likes

Hi @imagejan,

Thank you Jan for your investigation!

Romain