Created
May 10, 2022 09:21
-
-
Save ij96/6d1f98b4eacb50e9e1d90e661be5e967 to your computer and use it in GitHub Desktop.
Get TIFF image shape quickly, by reading the tags rather than the image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tifffile | |
def get_tiff_shape(im_path): | |
""" | |
Get TIFF image shape quickly, by reading the tags rather than the image. | |
""" | |
with tifffile.TiffFile(im_path) as tif: | |
c = len(tif.pages) | |
h = w = None | |
for tag in tif.pages[0].tags.values(): | |
if tag.name == 'ImageLength': | |
h = tag.value | |
elif tag.name == 'ImageWidth': | |
w = tag.value | |
return (c, h, w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment