Skip to content

read_tiff does not work for both non-imagej tiffs and greyscale tiffs #164

@BenCaiello

Description

@BenCaiello

Description
The read_tiff function seems like it will error for any non-imagej formatted image written by tifffile -- and perhaps any non-imagej tiff whatsoever -- as tifffile's read function will find the "imagej_metadata" attribute (which when not saved in imagej format = None) and that creates an error in NAVis, since NAVis expects the imagej_metadata attribute to not exist at all.

Secondarily, when I tried saving the image as with imagej metadata, because it was greyscale, navis still errored because of no support for greyscale / 2D tiffs (only 4D ZCYX tifs).

Is there a simple / alternate way to load numpy array data or .tiff image data into NAVis?

To Reproduce

import navis 
import tifffile
import numpy
directory = "C:/some/place/on/your/disc"
array = np.zeros([500,400])    ## should be any 2-dimensional grey-scale array which fails 
array = array[np.newaxis, np.newaxis,  :,  :]     ## trying to mimic "TCYX" order by adding axes changes nothing

#### Non-imageJ format fails:
tifffile.imwrite(directory, array)
navis.read_tiff(directory)

#### ImageJ format for greyscale / 2D fails:
tifffile.imwrite(directory, array.astype("uint8"), imagej = True, metadata = {})
navis.read_tiff(directory)
...

The arrays I'm trying to save are from an already skeletonized cell segmentations (hence the grayscale / 2D). What I've been working with tend to be small (smaller then the np.zeros faux-data in the example) because they are not necessarily neurons nor from very high resolution images. I have tried adding dimensions manually before saving to make them faux-4D, but somewhere in the save / load process they revert to 2D.

This error should apply to all non-imagej format tiffs:
image

This error should apply to greyscale imagej format tiffs:
image

Expected behavior
read_tiff reads tiffs

Your system

  • NAVis version: 1.7.0
    • tifffile: 2024.2.12
  • Python: 3.9
  • Operating System: windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions