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

imwrite or imread loses channel dimension #155

Closed
data2code opened this issue Sep 28, 2022 · 2 comments
Closed

imwrite or imread loses channel dimension #155

data2code opened this issue Sep 28, 2022 · 2 comments
Labels
question Further information is requested

Comments

@data2code
Copy link

data2code commented Sep 28, 2022

In the example below, I save a single channel 3D image ZCYX with imwrite. imread() returns a 3d array, the single channel is squeezed away.
This makes it difficult to know if the first axis is Z or C.

Thank you!

>>> img=(np.random.rand(10,1,100,100)*255).astype(np.uint8)
>>> img.shape
(10, 1, 100, 100)
>>> tifffile.imwrite("test.tiff", img, compression='zlib', metadata={'axes': "ZCYX"}, imagej=True)
>>> tifffile.imread("test.tiff").shape
(10, 100, 100)

For more than one channel, it's not a problem. Maybe there is a way for me to disable sequeeze?

>>> img=(np.random.rand(10,2,100,100)*255).astype(np.uint8)
>>> tifffile.imwrite("test.tiff", img, compression='zlib', metadata={'axes': "ZCYX"}, imagej=True)
>>> tifffile.imread("test.tiff").shape
(10, 2, 100, 100)
@cgohlke cgohlke added the question Further information is requested label Sep 28, 2022
@cgohlke
Copy link
Owner

cgohlke commented Sep 28, 2022

Try squeeze=False, which returns the array in TZCYXS order (most commonly for ImageJ):

>>> tifffile.imread("test.tiff", squeeze=False).shape
(1, 10, 1, 100, 100, 1)

@cgohlke cgohlke closed this as completed Sep 28, 2022
@cgohlke
Copy link
Owner

cgohlke commented Sep 28, 2022

See also #19 and #66.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants