DigitalSlideArchive / tifftools

Pure Python tools for reading and writing all TIFF IFDs, sub-IFDs, and tags.
Other
49 stars 5 forks source link

Examples of write tiffs from scratch, not inheriting info from an existing tiff #55

Closed dbuscombe-usgs closed 3 years ago

dbuscombe-usgs commented 3 years ago

Please could you provide more examples for how to use this tool to write tiffs from scratch? Thanks SO much for providing this tool. I really hope I can make it work for me!

Problem:

Alternatives tried:

So I'm really hoping I can use tifftools, but I cant figure out (from the one provided example) how to write a tiff entirely from scratch using arrays

Question: The provided example is useful, but only deals with the case where all the info is obtained from an existing file

info = tifftools.read_tiff(file)

But how would you create that info object from an numpy array, metadata, and exif separately? where metadata and exif are two separate dicts or JSON objects (or whatever)?

I also found this that helpfully explains how to add info to an existing tiff

In summary, I'm looking for advice for how to construct a viable info object that can be passed to .write_tif like this

tifftools.write_tif(info, ...)

where info is constructed from 1) a numpy array containing the image, 2) an array or dictionary of exif data, and 3) an array or dictionary of other metadata (tags)

manthey commented 3 years ago

Writing image data is outside the scope of tifftools.

I would use a library like pyvips to do it (see the pyvips.Image.new_from_memory method for converting numpy to vips). If you need to adjust metadata more than vips allowed, I'd take the output tiff from vips and manipulate it using tifftools or some other tool.

I'm closing this issue as writing image data is beyond what tifftools is ever intended to do.

dbuscombe-usgs commented 3 years ago

Ok, fair enough - thanks for responding. Good tip on the pyvips package