ome / bioformats

Bio-Formats is a Java library for reading and writing data in life sciences image file formats. It is developed by the Open Microscopy Environment. Bio-Formats is released under the GNU General Public License (GPL); commercial licenses are available from Glencoe Software.
https://www.openmicroscopy.org/bio-formats
GNU General Public License v2.0
381 stars 241 forks source link

Mouse over triggers an exception while saving virtual stack (Metamorph) #4067

Open dgault opened 1 year ago

dgault commented 1 year ago

Issue copied from https://github.com/imagej/ImageJ/issues/219

Originally opened by @bruvellu

Hello,

I ran into an intriguing error while saving a virtual Metamorph stack to TIFF. If I pass the mouse over another window (also a virtual stack), the saving fails with an exception Current file should not be null (see below).

It appears to be specific to the Metamorph format; it doesn't happen while saving a regular TIFF virtual stack to file. The dataset is a timelapse with multiple positions and slices. I can provide a subset if needed for debugging.

Steps:

Import the Metamorph (.nd) file using Bio-Formats Mark the checkbox to open as a virtual stack Select all series to be opened (stacks for different positions) Click on the window of a virtual stack and press CTRL+S to save as TIFF While the stack is being saved, mouse over the window of another stack An exception window pops-up and the saving halts Screencast:

257253544-3121eb4e-f083-403d-ae2d-fc0342946900.webm

Exception:

(Fiji Is Just) ImageJ 2.14.0/1.54f; Java 1.8.0_172 [64-bit]; Linux 3.10.0-1062.4.3.el7.x86_64; 1193MB of 120000MB (<1%)

java.lang.IllegalStateException: FormatReader.getImageCount: Current file should not be null; call setId(String) first
    at loci.formats.FormatTools.assertId(FormatTools.java:988)
    at loci.formats.FormatReader.getImageCount(FormatReader.java:685)
    at loci.formats.in.MetamorphReader.openBytes(MetamorphReader.java:329)
    at loci.formats.ChannelFiller.openBytes(ChannelFiller.java:167)
    at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:229)
    at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:161)
    at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
    at loci.formats.DimensionSwapper.openBytes(DimensionSwapper.java:233)
    at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
    at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
    at loci.formats.ReaderWrapper.openBytes(ReaderWrapper.java:334)
    at loci.plugins.util.ImageProcessorReader.openProcessors(ImageProcessorReader.java:186)
    at loci.plugins.util.ImageProcessorReader.openProcessors(ImageProcessorReader.java:83)
    at loci.plugins.util.BFVirtualStack.getProcessor(BFVirtualStack.java:185)
    at ij.io.ImageWriter.write16BitVirtualStack(ImageWriter.java:103)
    at ij.io.ImageWriter.write(ImageWriter.java:292)
    at ij.io.TiffEncoder.write(TiffEncoder.java:129)
    at ij.io.TiffEncoder.write(TiffEncoder.java:150)
    at ij.io.FileSaver.saveAsTiffStack(FileSaver.java:218)
    at ij.io.FileSaver.saveAsTiff(FileSaver.java:91)
    at ij.io.FileSaver.save(FileSaver.java:68)
    at ij.plugin.Commands.save(Commands.java:63)
    at ij.plugin.Commands.run(Commands.java:33)
    at ij.IJ.runPlugIn(IJ.java:216)
    at ij.Executer.runCommand(Executer.java:152)
    at ij.Executer.run(Executer.java:70)
    at java.lang.Thread.run(Thread.java:748)

@bruvellu : that error suggests that one of the underlying .tiff or .stk files could not be read. Are you able to open all of the planes in the dataset without a virtual stack, using the Specify range for each series option to open a subset of planes at a time?

Originally posted by @melissalinkert in https://github.com/imagej/ImageJ/issues/219#issuecomment-1660902628

Hi @ctrueden and @melissalinkert,

Yes, I'm able to open the datasets without a virtual stack. I also managed to save every individual series from virtual to TIFF, so it looks like all the .stk files are readable (as long as I don't pass the mouse over another window during the saving). Could it be that the mouse hovering confuses ImageJ as to which virtual slice it should be loading/writing?

Cheers

Originally posted by @bruvellu in https://github.com/imagej/ImageJ/issues/219#issuecomment-1661952761

The only additional thought that occurs to me is if this isn't a concurrency issue. If the call to save has a reader instance and the mouse over event attempts some setting on the same reader, the call to openBytes might catch the reader with its pants down.

Originally posted by @joshmoore in https://github.com/imagej/ImageJ/issues/219#issuecomment-1662247590

I have managed to reproduce the same issue, though I have not yet found the root cause of the problem. Iw ill try and test some more to see if I can locate the issue. I suspect it is going to be specific to the Bio-Formats virtual stack.

Originally posted by @dgault in https://github.com/imagej/ImageJ/issues/219#issuecomment-1664287222

dgault commented 1 year ago

So far I have been able to recreate the bug with mutiple formats, so it is not specific to MetaMorph, though the error message does differ between formats.

It also seems that it must be 2 series from the same image, I was unable to recreate the bug using 2 separate images.

I was also unable to recreate the issue using a standard Tiff Virtual Stack so it appears to be related to the BF plugin.

From debugging I suspect the series on the underlying reader is getting updated but I have been unable to catch the exact call so far.