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

Split and Merge by Python #95

Open
alexlsa opened this issue Jun 10, 2024 · 4 comments
Open

Split and Merge by Python #95

alexlsa opened this issue Jun 10, 2024 · 4 comments

Comments

@alexlsa
Copy link

alexlsa commented Jun 10, 2024

Hi,

Thanks for this project

Is it possible to run split and merge with python interface without using the filesystem ?

@manthey
Copy link
Contributor

manthey commented Jun 19, 2024

When you do tifftools.read_tiff(<buffer or path>) it returns a data structure that includes a list of the ifds (directories). split stores each directory as its own file; merge takes a list of ifds from a list of files are writes out the result.

You can reference individual ifds, and create a new list and then save it. For instance, this merges the first two ifds from a first source with the last two ifds from a second source. The sources and destinations can be paths or streams or io buffers. Depending on the actual contents of the sources, the program may use temp files as part of its processing.

info1 = tifftools.read_tiff(<source 1>)
info1['ifds']  # this is a list
info2 = tifftools.read_tiff(<source 2>)
mergedifds = info1['ifds'][:2] + info2['ifds'][-2:]
tifftools.write_tiff(merged_ifds, <destination>)

@alexlsa
Copy link
Author

alexlsa commented Jun 20, 2024

Thank you @manthey, it worked very well. Now I can remove any level (ifds) from source file

One small question : Is it possible to delete ifds without reading whole source file ? I mean, I do not want to read and write source file, because file is very big I just want to remove specific ifds from generic tif. All operations will be done on a single source file

@manthey
Copy link
Contributor

manthey commented Jun 21, 2024

tifftools won't do that -- it isn't within its design intent. But you can modify a tiff file to skip ifds. An ifd has a structure of

<location of next ifd or 0 to indicate last ifd>, so you could rewrite the 4 or 8 bytes of the location of the ifd you want to remove at the end of the preceding ifd to point to the next ifd.

@alexlsa
Copy link
Author

alexlsa commented Jul 4, 2024

Thank you,

Can I do this with tifftools ? or maybe python tifffile ?

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