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

Save metadata in tif files #20

Open
gabriel-ing opened this issue Mar 31, 2023 · 2 comments
Open

Save metadata in tif files #20

gabriel-ing opened this issue Mar 31, 2023 · 2 comments

Comments

@gabriel-ing
Copy link
Owner

At the moment only saving pixelsize and unit but it should be super simple to do (I actually have done this in 2 lines of code but not tested yet)

@gabriel-ing
Copy link
Owner Author

Took a lot more than 2 lines of code to fix this, I had an issue with unicode text not being saved in Tif files, so to fix this I changed any µ to u, but then just removed any unicode characters not present in ascii from the metadata. This still does not always work so requires further investigation.

@jrobsontull
Copy link

@gabriel-ing Looks like tifffile encodes the metadata to ascii before saving (see tifffile.py). If you are seeing unicode text in your metadata after reading the data in, sounds like you need to decode it first. In the first instance as a safety net before saving, you could decode and then encode to ascii, prior to tifffile.imsave().

for key in metadata.keys():
    value = metadata[key]
    metadata[key] = value.decode('some_encoding').encode('ascii', 'replace')

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

No branches or pull requests

2 participants