|
| 1 | +import os |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import tifffile |
| 5 | + |
| 6 | +from elf.parallel import seeded_watershed, distance_transform |
| 7 | + |
| 8 | +LOWER_RESOLUTION_DIR = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/lower_resolution" |
| 9 | + |
| 10 | +def dilate_sgns(in_path, out_path, dilation_distance, block_shape=[64, 128, 128], halo=[8, 16, 16]): |
| 11 | + print(f"Dilating {in_path} with dilation distance {dilation_distance}.") |
| 12 | + seg = tifffile.imread(in_path).astype("uint32") |
| 13 | + |
| 14 | + distances = distance_transform(seg == 0, halo=halo, sampling=(1, 1, 1), block_shape=block_shape, verbose=True) |
| 15 | + extension_mask = distances < dilation_distance |
| 16 | + |
| 17 | + extended_seg = np.zeros_like(seg) |
| 18 | + extended_seg = seeded_watershed( |
| 19 | + distances, seg, out=extended_seg, mask=extension_mask, block_shape=block_shape, halo=halo, verbose=True |
| 20 | + ) |
| 21 | + |
| 22 | + tifffile.imwrite(out_path, extended_seg.astype("float32"), bigtiff=True, compression="zlib") |
| 23 | + |
| 24 | + |
| 25 | +def main(): |
| 26 | + cochlea = "G_EK_000049_L" |
| 27 | + scale = 3 |
| 28 | + suffixes = ["_marker_positive", "_marker_negative", ""] |
| 29 | + dilation_distances = [2, 4] |
| 30 | + |
| 31 | + for suffix in suffixes: |
| 32 | + for dilation_distance in dilation_distances: |
| 33 | + in_path = os.path.join(f"{LOWER_RESOLUTION_DIR}", cochlea, f"scale{scale}", f"SGN_v2{suffix}.tif") |
| 34 | + out_path = os.path.join(f"{LOWER_RESOLUTION_DIR}", cochlea, f"scale{scale}", |
| 35 | + f"SGN_v2{suffix}_{scale}_dilated_{dilation_distance}.tif") |
| 36 | + dilate_sgns(in_path, out_path, dilation_distance) |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + main() |
0 commit comments