Skip to content

Commit

Permalink
Merge pull request #5 from dlesmesl/master
Browse files Browse the repository at this point in the history
Pyilastik tifffile transition
  • Loading branch information
pranjaldhole authored Jun 7, 2021
2 parents 13ed163 + b09da71 commit e5d5e3d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
35 changes: 26 additions & 9 deletions pyilastik/ilastik_storage_version_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pyilastik/tests/test_img_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e5d5e3d

Please sign in to comment.