imagej / ImageJ

Public domain software for processing and analyzing scientific images
http://imagej.org
Other
513 stars 218 forks source link

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

Closed bruvellu closed 11 months ago

bruvellu commented 11 months ago

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:

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

Screencast:

Screencast from 31-07-23 15:52:36.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)

Cheers, Bruno

ctrueden commented 11 months ago

@bruvellu That error is intriguing indeed!

CC @sbesson @dgault @melissalinkert @joshmoore to loop them in, since it is not clear whether the bug-fix will need to be on the Bio-Formats side or the ImageJ side.

melissalinkert commented 11 months ago

@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?

bruvellu commented 11 months ago

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

joshmoore commented 11 months ago

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.

dgault commented 11 months ago

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.

dgault commented 11 months ago

I have copied the issue to the Bio-Formats repo as I have been unable to reproduce with a standard Tiff Virtual Stack, so it indeed appears to be related specifically to Bio-Formats. You can close this ImageJ Issue in favour of the new Bio-Formats Issue.

bruvellu commented 11 months ago

Great, thanks @dgault!