Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imagej=True argument eats dimensions and complicates interpretation #66

Closed
amsikking opened this issue Feb 23, 2021 · 6 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@amsikking
Copy link

Hi there,

I've really enjoyed using tifffile for my microscope - thank you!

I often deal with data in a 'tzcyx' format and want to save with imagej=True. I've noticed a behavior that's tricky for me to deal with and I'm wondering if there's an easy fix to keep all dimensions?

Example script:

import numpy as np
from tifffile import imread, imwrite

def imwrite_imread(data):
    print('in :', data.shape)
    imwrite('data.tif', data, imagej=True)
    data_out = imread('data.tif')
    print('out:', data_out.shape)
    return data_out

data_1 = np.random.randint(0, 2**8, (1, 10, 1, 248, 260), 'uint8')
data_2 = np.random.randint(0, 2**8, (10, 1, 1, 248, 260), 'uint8')

imwrite_imread(data_1)
imwrite_imread(data_2)

Output:

in : (1, 10, 1, 248, 260)
out: (10, 248, 260)
in : (10, 1, 1, 248, 260)
out: (10, 248, 260)
>>> 
@cgohlke cgohlke added the duplicate This issue or pull request already exists label Feb 23, 2021
@cgohlke
Copy link
Owner

cgohlke commented Feb 23, 2021

Hello,

this is a duplicate of #19. Please see the discussion there. I am trying to find a way to preserve singlet dimensions with an optional keyword (in imread) that works with ImageJ, LSM, OME-TIFF...

@amsikking
Copy link
Author

Ah okay, thanks for getting back quickly. Yes a keyword argument for imread that supports singlet dimensions could work. It's kind of a deal breaker for my setup right now so I'd be very excited for a solution . Thanks for working on this!

@cgohlke
Copy link
Owner

cgohlke commented Feb 25, 2021

Hi @amsikking,

would the squeeze=False option work for you? That would return the ImageJ hyperstack in 6 dimensions in TZCYXS order (S is for Samples). E.g.

import numpy as np
from tifffile import imread, imwrite

def imwrite_imread(data):
    print('in :', data.shape)
    imwrite('data.tif', data, imagej=True)
    data_out = imread('data.tif', squeeze=False)
    print('out:', data_out.shape)
    return data_out

data_1 = np.random.randint(0, 2**8, (1, 10, 1, 248, 260), 'uint8')
data_2 = np.random.randint(0, 2**8, (10, 1, 1, 248, 260), 'uint8')

imwrite_imread(data_1)
imwrite_imread(data_2)
in : (1, 10, 1, 248, 260)
out: (1, 10, 1, 248, 260, 1)
in : (10, 1, 1, 248, 260)
out: (10, 1, 1, 248, 260, 1)

@amsikking
Copy link
Author

imread with squeeze=False is certainly more convenient than redefining imread with a call to transpose_axes each time. Could squeeze=False be the kwarg default? and with a default behavior of out.shape == in.shape?

(apologies in advance if these are silly questions, my knowledge of tiff's is very shallow so I'm just approaching this from a 'user' viewpoint!)

@cgohlke
Copy link
Owner

cgohlke commented Feb 26, 2021

out.shape == in.shape cannot be achieved without extending the ImageJ format. Use the default tifffile format for that. squeeze=False as default will likely break most existing applications.

@cgohlke
Copy link
Owner

cgohlke commented Feb 26, 2021

Closed in v2021.2.26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants