Bio-Formats export as ICS1/2 fails when cropping more than one dimension

Dear @OMETeam,

I would like to open an image with Bio-Formats (tested 6.4.1) and export a subset as *.ics, see below IJ-macro using the Mitosis example dataset, i.e. from 2C, 5Z, 51T to 1C, 5Z, 10T:

#@ File (style="directory") directory


run("Mitosis (26MB, 5D stack)");
saveAs("Tiff", directory + "/mitosis.tif");
close();

filelist = getFileList(directory) 
for (i = 0; i < lengthOf(filelist); i++) {
    if (endsWith(filelist[i], ".tif")) { 
    	infile = directory + "/" + filelist[i];
    	print(infile);
        run("Bio-Formats Importer", "open="+ infile +" color_mode=Default rois_import=[ROI manager] specify_range view=Hyperstack stack_order=XYCZT c_begin=1 c_end=1 c_step=1 z_begin=1 z_end=5 z_step=1 t_begin=1 t_end=10 t_step=1");
        outfile = directory + "/" + replace(filelist[i], ".tif", "_crop.ics");
        print("now saving: " + filelist[i]);
        run("Bio-Formats Exporter", "save=" + outfile);
        run("Close All");
    } 
}
print("All Done");

This fails with the error message posted below for both ICS1 and ICS2, but not for other formats like for example *.tiff or *.tf8. For downstream processing however, I need an ICS 1 or ICS2 file.

(Fiji Is Just) ImageJ 2.0.0-rc-69/1.52p; Java 1.8.0_172 [64-bit]; Windows 10 10.0; 130MB of 27569MB (<1%)
 
java.lang.ArrayIndexOutOfBoundsException: 50
	at loci.formats.out.ICSWriter.saveBytes(ICSWriter.java:137)
	at loci.formats.FormatWriter.saveBytes(FormatWriter.java:132)
	at loci.plugins.out.Exporter.run(Exporter.java:847)
	at loci.plugins.LociExporter.run(LociExporter.java:75)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
	at ij.IJ.runUserPlugIn(IJ.java:232)
	at ij.IJ.runPlugIn(IJ.java:193)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:312)
	at ij.IJ.run(IJ.java:323)
	at ij.macro.Functions.doRun(Functions.java:624)
	at ij.macro.Functions.doFunction(Functions.java:97)
	at ij.macro.Interpreter.doStatement(Interpreter.java:275)
	at ij.macro.Interpreter.doBlock(Interpreter.java:671)
	at ij.macro.Interpreter.doStatement(Interpreter.java:320)
	at ij.macro.Interpreter.doIf(Interpreter.java:1049)
	at ij.macro.Interpreter.doStatement(Interpreter.java:296)
	at ij.macro.Interpreter.doBlock(Interpreter.java:671)
	at ij.macro.Interpreter.doStatement(Interpreter.java:320)
	at ij.macro.Interpreter.doFor(Interpreter.java:593)
	at ij.macro.Interpreter.doStatement(Interpreter.java:302)
	at ij.macro.Interpreter.doStatements(Interpreter.java:261)
	at ij.macro.Interpreter.run(Interpreter.java:157)
	at ij.macro.Interpreter.run(Interpreter.java:91)
	at ij.macro.Interpreter.run(Interpreter.java:102)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:148)
	at ij.IJ.runMacro(IJ.java:137)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1108)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1104)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1055)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1104)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:147)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:228)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Saving as ics seems to work fine if only a single dimension is cropped this way, e.g. using the above code with c_end=2 works.

Thanks for your time!
Cheers,
Kai

1 Like

Thanks for raising the issue Kai, that looks like it is likely a bug in the ICSWriter. Would you be able to upload the sample file used to https://www.openmicroscopy.org/qa2/qa/upload/ for testing the issue and any potential fix?

thanks for the reply @dgault!

I have just uploaded the file “mitosis.tif” with the link you provided.
Alternatively you can get it directly from Fiji since its one of the sample images: File > Open Samples > Mitosis (26MB, 5D stack)
Thank you for the support on the amazing Bio-Formats! Kai

I have been able to reproduce the issue exactly as described using the latest Bio-Formats and it does appear to be a bug in the ICS Writer. I have opened a GitHub Issue to track the bug: https://github.com/ome/bioformats/issues/3539

As a workaround if it is required to save the cropped range to ICS it appears that first saving the cropped range to TIFF or OME-TIFF and then converting that file to ICS does work as expected. This is definitely not convenient but may be a temporary workaround if required.

Hi David,

thanks for reproducing the bug and creating the issue!
In the meantime I found an alternative workaround that uses SCIFIO to save the image as ICS1:

1 Like