Skip to content

Commit 4432c88

Browse files
committed
Removed relabeling, added ID offset
1 parent 3b650f7 commit 4432c88

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

scripts/export_lower_resolution.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import argparse
22
import os
3+
import warnings
34

45
import numpy as np
56
import pandas as pd
67
import tifffile
78
import zarr
89

910
from flamingo_tools.s3_utils import get_s3_path, BUCKET_NAME, SERVICE_ENDPOINT
10-
from skimage.segmentation import relabel_sequential
1111

1212

1313
def filter_component(fs, segmentation, cochlea, seg_name, components):
@@ -19,10 +19,11 @@ def filter_component(fs, segmentation, cochlea, seg_name, components):
1919
# Then we get the ids for the components and us them to filter the segmentation.
2020
component_mask = np.isin(table.component_labels.values, components)
2121
keep_label_ids = table.label_id.values[component_mask].astype("int64")
22+
if max(keep_label_ids) > np.iinfo("uint16").max:
23+
warnings.warn(f"Label ID exceeds maximum of data type 'uint16': {np.iinfo("uint16").max}.")
24+
2225
filter_mask = ~np.isin(segmentation, keep_label_ids)
2326
segmentation[filter_mask] = 0
24-
25-
segmentation, _, _ = relabel_sequential(segmentation)
2627
segmentation = segmentation.astype("uint16")
2728
return segmentation
2829

scripts/export_synapse_detections.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tqdm import tqdm
1313

1414

15-
def export_synapse_detections(cochlea, scale, output_folder, synapse_name, reference_ihcs, max_dist, radius):
15+
def export_synapse_detections(cochlea, scale, output_folder, synapse_name, reference_ihcs, max_dist, radius, id_offset):
1616
s3 = create_s3_target()
1717

1818
content = s3.open(f"{BUCKET_NAME}/{cochlea}/dataset.json", mode="r", encoding="utf-8")
@@ -64,15 +64,18 @@ def export_synapse_detections(cochlea, scale, output_folder, synapse_name, refer
6464
):
6565
bb = tuple(slice(c - radius, c + radius + 1) for c in coord)
6666
try:
67-
output[bb][mask] = matched_ihc
67+
output[bb][mask] = matched_ihc + id_offset
6868
except IndexError:
6969
print("Index error for", coord)
7070
continue
7171

7272
# Write the output.
7373
out_folder = os.path.join(output_folder, cochlea, f"scale{scale}")
7474
os.makedirs(out_folder, exist_ok=True)
75-
out_path = os.path.join(out_folder, f"{synapse_name}.tif")
75+
if id_offset != 0:
76+
out_path = os.path.join(out_folder, f"{synapse_name}_offset{id_offset}.tif")
77+
else:
78+
out_path = os.path.join(out_folder, f"{synapse_name}.tif")
7679
print("Writing synapses to", out_path)
7780
tifffile.imwrite(out_path, output, bigtiff=True, compression="zlib")
7881

@@ -82,16 +85,18 @@ def main():
8285
parser.add_argument("--cochlea", "-c", required=True)
8386
parser.add_argument("--scale", "-s", type=int, required=True)
8487
parser.add_argument("--output_folder", "-o", required=True)
85-
parser.add_argument("--synapse_name", default="synapse_v3_ihc_v4")
86-
parser.add_argument("--reference_ihcs", default="IHC_v4")
88+
parser.add_argument("--synapse_name", default="synapse_v3_ihc_v4b")
89+
parser.add_argument("--reference_ihcs", default="IHC_v4b")
8790
parser.add_argument("--max_dist", type=float, default=3.0)
8891
parser.add_argument("--radius", type=int, default=3)
92+
parser.add_argument("--id_offset", type=int, default=0)
8993
args = parser.parse_args()
9094

9195
export_synapse_detections(
9296
args.cochlea, args.scale, args.output_folder,
9397
args.synapse_name, args.reference_ihcs,
94-
args.max_dist, args.radius
98+
args.max_dist, args.radius,
99+
args.id_offset,
95100
)
96101

97102

0 commit comments

Comments
 (0)