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

Combine multiple metamorph files into sinlge .tif file #3186

Open hummuscience opened 6 years ago

hummuscience commented 6 years ago

I am trying to concatenate a time series of MetaMorph files into a singe .tif file with bfconvert (command line tool) but cannot make it work.

Is it at all possible? If so, what is the correct syntax?

This is what I am trying:

./bfconvert ~/mnt/Muad/ca-imaging/20180517/6tg-ko/ 6tg-ko.tif
/home/generalubuntu/mnt/Muad/ca-imaging/20180517/6tg-ko/
Exception in thread "main" java.io.FileNotFoundException: /home/generalubuntu/mnt/Muad/ca-imaging/20180517/6tg-ko (Is a directory)
    at java.io.RandomAccessFile.open0(Native Method)
    at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
    at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:123)
    at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:139)
    at loci.common.NIOFileHandle.<init>(NIOFileHandle.java:148)
    at loci.common.Location.getHandle(Location.java:324)
    at loci.common.Location.getHandle(Location.java:294)
    at loci.common.Location.getHandle(Location.java:284)
    at loci.common.Location.getHandle(Location.java:274)
    at loci.common.Location.checkValidId(Location.java:349)
    at loci.formats.ImageReader.getReader(ImageReader.java:177)
    at loci.formats.ImageReader.setId(ImageReader.java:839)
    at loci.formats.tools.ImageConverter.testConvert(ImageConverter.java:385)
    at loci.formats.tools.ImageConverter.main(ImageConverter.java:884)

these files can be used as example:

https://www.dropbox.com/s/2xvxycbwvm9p85k/test-series.zip?dl=0

sbesson commented 6 years ago

Hi @Cumol, the Bio-Formats command-line tools and more generally IFormatReader.setId method is expecting a file as the input and will not handle directories as suggested by the exception.

Converting Metamorph files into a single (OME-)TIFF should definitely work as long as you point the bfconvert utility to one of the files consituting the fileset.

Using your test files and Bio-Formats 5.9.0, the two commands below should produce a single OME-TIFF and TIFF image:

sbesson@ls30630:Downloads $ bfconvert 23.001 23.ome.tiff
23.001
MetamorphTiffReader initializing 23.001
Reading IFDs
Populating metadata
Populating OME metadata
[Metamorph TIFF] -> 23.ome.tiff [OME-TIFF]
    Converted 1/10 planes (10%)
    Converted 10/10 planes (100%)
[done]
6.068s elapsed (3.5+325.3ms per plane, 1761ms overhead)
sbesson@ls30630:Downloads $ bfconvert 23.001 23.tiff
23.001
MetamorphTiffReader initializing 23.001
Reading IFDs
Populating metadata
Populating OME metadata
[Metamorph TIFF] -> 23.tiff [Tagged Image File Format]
    Converted 1/10 planes (10%)
    Converted 10/10 planes (100%)
[done]
6.69s elapsed (3.9+216.6ms per plane, 3615ms overhead)
hummuscience commented 6 years ago

@sbesson wanted to try it out and wondered why it still gives the same error. It seems like th command line tools on the website are still the older version:

https://docs.openmicroscopy.org/bio-formats/5.8.2/users/comlinetools/index.html

When I run bfconvert -version it outputs 5.6.0 (from August 2017)

Additional question. What determines the speed of conversion? RAM? Number of processes?

hummuscience commented 6 years ago

I tried one full dataset and was able to convert it correctly.

Then tried another one and got the following output:

23.001
MetamorphTiffReader initializing 23.001
Reading IFDs
Populating metadata
Populating OME metadata
Error reading IFD type at: 6
Exception in thread "main" java.lang.NullPointerException
    at loci.common.xml.XMLTools.sanitizeXML(XMLTools.java:298)
    at loci.formats.in.MetamorphTiffReader.parseFile(MetamorphTiffReader.java:628)
    at loci.formats.in.MetamorphTiffReader.initFile(MetamorphTiffReader.java:217)
    at loci.formats.FormatReader.setId(FormatReader.java:1397)
    at loci.formats.ImageReader.setId(ImageReader.java:842)
    at loci.formats.tools.ImageConverter.testConvert(ImageConverter.java:385)
    at loci.formats.tools.ImageConverter.main(ImageConverter.java:884)

currently trying to find out how to replicate this with a small number of files

UPDATE: the first 10 files are converted properly. I wonder what is causing the issue. If it is one of th 15k files that follow, it might be hard to find out which. Is there a way to "skip" corrupt files?

dgault commented 6 years ago

With regards the version, are you running the command from the bftools folder? Using the link you had in https://docs.openmicroscopy.org/bio-formats/5.8.2/users/comlinetools/index.html I get the below: ./bfconvert -version Version: 5.8.2 Build date: 20 April 2018 VCS revision: 07ecd9a5d239985f8ae57462c12124c2fa5ccd9b

As for the error message, the MetamorphTiffReader expects the files to contain a blob of XML metadata in the Image Description. That particular error would suggest that this is missing. If you have the libtiff tools you can check the file using tiffinfo, this will print out the TIFF IFD metadata and you should see the XML blob in Image Description.