glencoesoftware / bioformats2raw

Bio-Formats image file format to raw format converter
GNU General Public License v2.0
77 stars 35 forks source link

Channel mass up into timestep #205

Closed tymiao1220 closed 1 year ago

tymiao1220 commented 1 year ago

Hi, we currently encounter a problem using bioformat2raw to convert multi-channel tiff with more than 5 channels.

The problem is that it will be converted to multi-timestep instead of multi-channel, and from the METADATA.ome.xml we found that sizeC=1 and sizeT=5 instead of sizeC=5 and sizeT=1.

What we did is to use the command line bioformats2raw bigtiff_5c.tif bigtiff_5c.tif.pyramid --max-worker 32 -p.

We are using tifffile (https://github.com/cgohlke/tifffile) library to combine different stain images(tif) all together to a large array [1, 5, 1, x, y] where 5 is the channel and save it to a single .tif and than using bioformat2raw to convert them.

With this pipeline, we can make it work for the channel less than 5.

Do you have any suggestions or workaround?

melissalinkert commented 1 year ago

Usually channels (or Z sections) being detected as timepoints means that there is not enough metadata in the TIFF file to set the dimensions correctly. Bio-Formats defaults to treating all planes in a TIFF file as timepoints, in the absence of any other metadata.

This typically isn't a bug in bioformats2raw, and most often isn't a bug in Bio-Formats either. You'll need to make sure that the original data is written in a way that Bio-Formats can detect that the 5 planes are channels.

One option is to write each channel as a separate TIFF file (e.g. bigtiff_c0.tif, bigtiff_c1.tif, ...) and then use a .pattern file to group them together - see also https://github.com/glencoesoftware/bioformats2raw/issues/130.

Another option is to add channel metadata when writing with tifffile. Writing either ImageJ-style metadata or OME-TIFF should work, and https://github.com/cgohlke/tifffile#examples has examples of both. ImageJ-style is usually simpler if you just want to record that the planes are channels, but don't need to specify channel names, colors, etc.

melissalinkert commented 1 year ago

Closing as this is an input data issue, not something we can fix in bioformats2raw.