I am writing this gist to leave a script that show how tifffile interprets the tags of tiff of image width and image height and how that translates to the array access pattern.
According to the TIFF specification:
- Tag 256 (ImageWidth): Number of columns (horizontal extent, X axis) = width
- Tag 257 (ImageLength): Number of rows (vertical extent, Y axis) = height
For the file scanimage_20220923_roi.tif (256×528 pixels):
import tifffile
with tifffile.TiffFile('scanimage_20220923_roi.tif') as tif:
page = tif.pages[0]
# TIFF tags show the standard convention
print(f"ImageWidth (Tag 256): {page.imagewidth}") # 256 (columns, X, width)
print(f"ImageLength (Tag 257): {page.imagelength}") # 528 (rows, Y, height)
# Array shape follows (height, width) convention
print(f"Array shape: {page.shape}") # (528, 256) = (height, width)
print(f"Axes: {page.axes}") # 'YX'
# Load as NumPy array
data = page.asarray()
print(f"Data shape: {data.shape}") # (528, 256) = (height, width)
# Access pattern: data[row, column] = data[y, x] = data[height_idx, width_idx]
pixel = data[264, 128] # Row 264, Column 128Output:
ImageWidth (Tag 256): 256
ImageLength (Tag 257): 528
Array shape: (528, 256)
Axes: 'YX'
Data shape: (528, 256)
- TIFF standard: ImageWidth=256 (width), ImageLength=528 (height)
- Array shape: (528, 256) = (height, width) - height comes first
- Indexing:
data[y, x]ordata[row, column]where first index is height dimension - Memory layout: C-order (row-major) makes width the fast-varying dimension