I just stumbled upon a weird situation with skimage.io.imread
.
I was trying to open a MultiPage TIFF (dimensions: 96x512x512) like this:
import argparse
from pathlib import Path
import numpy as np
from skimage import io
def numpy_array_from_file(path):
""" method to load numpy array from tiff file"""
im_data = io.imread(path)
print ("image dimensions {}".format(im_data.shape))
return im_data
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Extract page from a MultiPage TIFF")
parser.add_argument("tiff_file", type=str, help="3D TIFF file to open)")
args = parser.parse_args()
tiff_file = Path(args.tiff_file).absolute()
numpy_array_from_file(tiff_file)
And I was obtaining in the output:
image dimensions (512, 512)
After trying many different things (because I was sure that my input image had 96 pages), I discovered that the problem was to use directly Path
in the numpy_array_from_file
instead of using a string. By changing the last line to:
numpy_array_from_file(str(tiff_file))
I got the expected:
image dimensions (96, 512, 512)
So, my question is ... Anyone know why I had that behaviour? I am not very experienced in python, but I would have expected to obtain an error if Path
was not appropriate in that situation.