Bfconvert vs. Bio-Formats Exporter Issue

Hi all,

I have a strange issue using bfconvert (from within a python script) when converting a CZI image file. The script itself works fine and the output is:

Original ImageFile :  C:\test_bfconvert\CH=3
ImageFile OME.TIFF :  C:\test_bfconvert\CH=3.ome.tiff
ImageFile OEM.XML  :  C:\test_bfconvert\CH=3.ome.xml
Use CMD :  bfconvert -no-upgrade -option zeissczi.attachments false -option zeissczi.autostitch true -option ometiff.companion "C:\test_bfconvert\CH=3.ome.xml" "C:\test_bfconvert\CH=3.czi" "C:\test_bfconvert\CH=3.ome.tiff"
C:\test_bfconvert\CH=3.czi
ZeissCZIReader initializing C:\test_bfconvert\CH=3.czi
Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
Unknown IlluminationType value 'Fluorescence' will be stored as "Other"
[Zeiss CZI] -> C:\test_bfconvert\CH=3.ome.tiff [OME-TIFF]
        Converted 3/3 planes (100%)
[done]
10.137s elapsed (60.0+345.33334ms per plane, 5818ms overhead)

And I also open the original CZI in Fiji (latest BioFormats) and saved it as an OME-TIFF.

But when I try to open the OME-TIFF (created by bfconvert) in ZEN I get error messages, while opening the OME-TIFF (created by Fiji) works fine in ZEN.

So my questions is what the difference is between creating an OME-TIFF using bfconvert vs. open the image in Fiji via BioFormats and exporting it as an OME-TIFF.

What error messages are you specifically seeing? I wouldn’t have expected any noticeable differences between the 2 files.

If you run showinf -nopix -omexml myTestFile.ome.tiff against the two different files are there any obvious differences there?

Found the issue. Our Zen software was not configured correctly to read an OME-TIFF plus companion OMEXML.

Now it works fine.

Here is the simple code I use now (maybe somebody finds it useful). No guarantee this works for all cases …

def get_fname_woext(filepath):

    # create empty string
    real_extension = ''

    # get all part of the file extension
    sufs = Path(filepath).suffixes
    for s in sufs:
        real_extension = real_extension + s

    # remover real extension from filepath
    filepath_woext = filepath.replace(real_extension, '')

    return filepath_woext


def convert_to_ometiff(imagefilepath,
                       bftoolsdir='/Users/bftools',
                       czi_include_attachments=False,
                       czi_autostitch=True,
                       verbose=True):

    # check if path exits
    if not os.path.exists(bftoolsdir):
        print('No bftools dirctory found. Nothing will be converted')
        file_ometiff = None

    if os.path.exists(bftoolsdir):

        # set working dir
        os.chdir(bftoolsdir)

        # get the imagefile path without extension
        imagefilepath_woext = get_fname_woext(imagefilepath)

        # create imagefile path for OME.TIFF
        file_ometiff = imagefilepath_woext + '.ome.tiff'

        # create cmdstring for CZI files- mind the spaces !!!
        if imagefilepath.lower().endswith('.czi'):

            # configure the CZI options
            if czi_include_attachments:
                czi_att = 'true'
            if not czi_include_attachments:
                czi_att = 'false'

            if czi_autostitch:
                czi_stitch = 'true'
            if not czi_autostitch:
                czi_stitch = 'false'

            # create cmdstring - mind the spaces !!!
            cmdstring = 'bfconvert -no-upgrade -option zeissczi.attachments ' + czi_att + ' -option zeissczi.autostitch ' + \
                czi_stitch + ' "' + imagefilepath + '" "' + file_ometiff + '"'

        else:
            # create cmdstring for non-CZIs- mind the spaces !!!
            cmdstring = 'bfconvert -no-upgrade' + ' "' + imagefilepath + '" "' + file_ometiff + '"'

        if verbose:
            print('Original ImageFile : ', imagefilepath_woext)
            print('ImageFile OME.TIFF : ', file_ometiff)
            print('Use CMD : ', cmdstring)

        # run the bfconvert tool with the specified parameters
        os.system(cmdstring)
        print('Done.')

    return file_ometiff
2 Likes