diff --git a/pyilastik/ilastik_storage_version_01.py b/pyilastik/ilastik_storage_version_01.py index 58e7bcf..d9bad55 100644 --- a/pyilastik/ilastik_storage_version_01.py +++ b/pyilastik/ilastik_storage_version_01.py @@ -3,28 +3,45 @@ import functools import warnings import numpy as np -from bigtiff import Tiff import pyilastik.utils as utils from functools import lru_cache +from tifffile import memmap, TiffFile + # image shape: (?,?,H,W,C), e.g. (1, 1, 2098, 2611, 3) # labels shape: (?,?,H,W,1), e.g. (1, 1, 2098, 2611, 1), 0 == unlabeled # prediction shape: (?,?,H,W,L), e.g. (1, 1, 2098, 2611, 3) +def fix_dims(memmap_array, path): + """""" + # target dims (Z,Y,X,C) + with TiffFile(path) as tif: + axes = tif.series[0].axes + + # Adding the missed axis + # changing S for C (some metadata has S as channels) + axes = axes.translate(axes.maketrans('S', 'C')) + if 'C' not in axes: + memmap_array = np.expand_dims(memmap_array, axis=-1) + axes += 'C' + if 'Z' not in axes: + memmap_array = np.expand_dims(memmap_array, axis=0) + axes = 'Z' + axes + + # Sorting the axes + dim_map = ['ZYXC'.index(dim) for dim in axes] + memmap_array = np.moveaxis(memmap_array, (0, 1, 2, 3), dim_map) + return memmap_array + + def imread(path): ''' reads tiff image in dimension order zyxc ''' - slices = Tiff.memmap_tcz(path) - - img = [] - for C in range(slices.shape[1]): - img.append(np.stack([s for s in slices[0, C, :]])) - img = np.stack(img) - img = np.moveaxis(img, (0, 1, 2, 3), (3, 0, 1, 2)) - return img + slices = memmap(path) + return fix_dims(slices, path) def is_overlap(tile_pos, block_pos): diff --git a/pyilastik/tests/test_img_import.py b/pyilastik/tests/test_img_import.py index d3ccd8f..9756436 100644 --- a/pyilastik/tests/test_img_import.py +++ b/pyilastik/tests/test_img_import.py @@ -4,7 +4,6 @@ from numpy.testing import assert_array_equal import pyilastik from pyilastik.ilastik_storage_version_01 import imread -from bigtiff import Tiff, PlaceHolder data_path = path = os.path.join(os.path.dirname(__file__), 'data/dimensionstest') diff --git a/setup.py b/setup.py index be816fb..6f4dbc7 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ reqs = ['h5py==2.10.0', 'numpy>=1.12.1', 'docopt>=0.6.2', - 'bigtiff>=0.1.1'] + 'tifffile'] def readme(): README_md = os.path.join(os.path.dirname(__file__), 'README.md')