Skip to content

Commit d0d41ec

Browse files
committed
Adaptations for handling tif files
1 parent f2355d5 commit d0d41ec

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

flamingo_tools/segmentation/unet_prediction.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ def run_unet_prediction(
403403

404404
def run_unet_prediction_preprocess_slurm(
405405
input_path: str,
406-
input_key: Optional[str],
407406
output_folder: str,
407+
input_key: Optional[str] = None,
408408
s3: Optional[str] = None,
409409
s3_bucket_name: Optional[str] = None,
410410
s3_service_endpoint: Optional[str] = None,
@@ -417,8 +417,8 @@ def run_unet_prediction_preprocess_slurm(
417417
418418
Args:
419419
input_path: The path to the input data.
420-
input_key: The key / internal path of the image data.
421420
output_folder: The output folder for storing the segmentation related data.
421+
input_key: The key / internal path of the image data.
422422
s3: Flag for considering input_path fo S3 bucket.
423423
s3_bucket_name: S3 bucket name.
424424
s3_service_endpoint: S3 service endpoint.
@@ -437,9 +437,9 @@ def run_unet_prediction_preprocess_slurm(
437437

438438
def run_unet_prediction_slurm(
439439
input_path: str,
440-
input_key: Optional[str],
441440
output_folder: str,
442441
model_path: str,
442+
input_key: Optional[str] = None,
443443
scale: Optional[float] = None,
444444
block_shape: Optional[Tuple[int, int, int]] = None,
445445
halo: Optional[Tuple[int, int, int]] = None,
@@ -453,9 +453,9 @@ def run_unet_prediction_slurm(
453453
454454
Args:
455455
input_path: The path to the input data.
456-
input_key: The key / internal path of the image data.
457456
output_folder: The output folder for storing the segmentation related data.
458457
model_path: The path to the model to use for segmentation.
458+
input_key: The key / internal path of the image data.
459459
scale: A factor to rescale the data before prediction.
460460
By default the data will not be rescaled.
461461
block_shape: The block-shape for running the prediction.
@@ -501,7 +501,11 @@ def run_unet_prediction_slurm(
501501

502502

503503
# does NOT need GPU, FIXME: only run on CPU
504-
def run_unet_segmentation_slurm(output_folder: str, min_size: int) -> None:
504+
def run_unet_segmentation_slurm(
505+
output_folder: str,
506+
min_size: int,
507+
boundary_distance_threshold: float = 0.5,
508+
) -> None:
505509
"""Create segmentation from prediction.
506510
507511
Args:
@@ -510,4 +514,5 @@ def run_unet_segmentation_slurm(output_folder: str, min_size: int) -> None:
510514
"""
511515
min_size = int(min_size)
512516
pmap_out = os.path.join(output_folder, "predictions.zarr")
513-
distance_watershed_implementation(pmap_out, output_folder, min_size=min_size)
517+
distance_watershed_implementation(pmap_out, output_folder, boundary_distance_threshold=boundary_distance_threshold,
518+
min_size=min_size)

scripts/extract_block.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def main(
6262
basename = input_content[0] + resized_suffix
6363
else:
6464
basename = "".join(input_content[-1].split(".")[:-1])
65+
image_prefix = basename.split("_")[-1]
6566

6667
input_dir = input_path.split(basename)[0]
6768
input_dir = os.path.abspath(input_dir)
@@ -93,6 +94,9 @@ def main(
9394
with zarr.open(s3_path, mode="r") as f:
9495
raw = f[input_key][roi]
9596

97+
elif ".tif" in input_path:
98+
raw = read_tif(input_path)[roi]
99+
96100
else:
97101
with zarr.open(input_path, mode="r") as f:
98102
raw = f[input_key][roi]

0 commit comments

Comments
 (0)