Skip to content

Commit

Permalink
tiff to zarr util
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreicher committed Nov 29, 2023
1 parent 19ab851 commit 175aeea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/autoseg/train_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ def train_model(
model_type: str = "MTLSD",
iterations: int = 100000,
warmup: int = 100000,
raw_file: str = "path/to/.zarr/or/.n5",
raw_file: str = "path/to/.zarr/or/.n5/or/.tiff",
out_file: str = "./raw_predictions.zarr",
voxel_size: int = 33,
save_every=2500,
) -> None:

# TODO: call ztools to rewrite .tiff file to zarr format
model_type = model_type.lower()
if model_type == "mtlsd":
mtlsd_train(
Expand Down
36 changes: 36 additions & 0 deletions src/autoseg/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import numpy as np
from funlib.persistence import prepare_ds
from funlib.geometry import Coordinate, Roi
import tifffile


neighborhood: list[list[int]] = [
[1, 0, 0],
[0, 1, 0],
Expand All @@ -15,3 +21,33 @@
[0, 10, 0],
[0, 0, 10],
]

def tiff_to_zarr(tiff_file:str="path/to/.tiff",
out_file:str="path/to/.zarr",
out_ds:str="path/to/volume",
voxel_size: int = 33,
offset: int = 0,
dtype=np.uint8,
transpose:bool=False) -> None:
tiff_stack: np.ndarray = tifffile.imread(tiff_file)
if transpose:
tiff_stack = np.transpose(tiff_stack, (2, 1, 0))

voxel_size: Coordinate = Coordinate((voxel_size)*3)
roi: Roi = Roi(offset=(offset)*3, shape=tiff_stack.shape * np.array(voxel_size))

print("Roi: ", roi)
voxel_size: Coordinate = Coordinate(100, 100, 100)

ds = prepare_ds(
filename=out_file,
ds_name=out_ds,
total_roi=roi,
voxel_size=voxel_size,
dtype=dtype,
delete=True,
)

ds[roi] = tiff_stack

print("TIFF Image stack saved as Zarr dataset.")

0 comments on commit 175aeea

Please sign in to comment.