Skip to content

Commit 07d23b5

Browse files
committed
Update parameters for LaVision SGN segmentation
1 parent cb554bc commit 07d23b5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

flamingo_tools/segmentation/postprocessing.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def components_sgn(
367367
threshold_erode: Optional[float] = None,
368368
min_component_length: int = 50,
369369
max_edge_distance: float = 30,
370-
iterations_erode: Optional[int] = None,
370+
iterations_erode: int = 0,
371371
postprocess_threshold: Optional[float] = None,
372372
postprocess_components: Optional[List[int]] = None,
373373
) -> List[List[int]]:
@@ -379,7 +379,7 @@ def components_sgn(
379379
threshold_erode: Threshold of column value after erosion step with spatial statistics.
380380
min_component_length: Minimal length for filtering out connected components.
381381
max_edge_distance: Maximal distance in micrometer between points to create edges for connected components.
382-
iterations_erode: Number of iterations for erosion, normally determined automatically.
382+
iterations_erode: Number of iterations for erosion.
383383
postprocess_threshold: Post-process graph connected components by searching for points closer than threshold.
384384
postprocess_components: Post-process specific graph connected components ([0] for largest component only).
385385
@@ -388,7 +388,7 @@ def components_sgn(
388388
"""
389389
if keyword not in table:
390390
distance_avg = nearest_neighbor_distance(table, n_neighbors=100)
391-
table[keyword] = list(distance_avg)
391+
table.loc[:, keyword] = list(distance_avg)
392392

393393
centroids = list(zip(table["anchor_x"], table["anchor_y"], table["anchor_z"]))
394394
labels = [int(i) for i in list(table["label_id"])]
@@ -397,18 +397,16 @@ def components_sgn(
397397
distance_nn.sort()
398398

399399
if len(table) < 20000:
400-
iterations = iterations_erode if iterations_erode is not None else 0
401400
min_cells = None
402401
average_dist = int(distance_nn[int(len(table) * 0.8)])
403402
threshold = threshold_erode if threshold_erode is not None else average_dist
404403
else:
405-
iterations = iterations_erode if iterations_erode is not None else 15
406404
min_cells = 20000
407405
threshold = threshold_erode if threshold_erode is not None else 40
408406

409-
if iterations != 0:
407+
if iterations_erode != 0:
410408
print(f"Using threshold of {threshold} micrometer for eroding segmentation with keyword {keyword}.")
411-
new_subset = erode_subset(table.copy(), iterations=iterations,
409+
new_subset = erode_subset(table.copy(), iterations=iterations_erode,
412410
threshold=threshold, min_cells=min_cells, keyword=keyword)
413411
else:
414412
new_subset = table.copy()
@@ -454,7 +452,7 @@ def label_components_sgn(
454452
threshold_erode: Optional[float] = None,
455453
min_component_length: int = 50,
456454
max_edge_distance: float = 30,
457-
iterations_erode: Optional[int] = None,
455+
iterations_erode: int = 0,
458456
postprocess_threshold: Optional[float] = None,
459457
postprocess_components: Optional[List[int]] = None,
460458
) -> List[int]:
@@ -466,7 +464,7 @@ def label_components_sgn(
466464
threshold_erode: Threshold of column value after erosion step with spatial statistics.
467465
min_component_length: Minimal length for filtering out connected components.
468466
max_edge_distance: Maximal distance in micrometer between points to create edges for connected components.
469-
iterations_erode: Number of iterations for erosion, normally determined automatically.
467+
iterations_erode: Number of iterations for erosion.
470468
postprocess_threshold: Post-process graph connected components by searching for points closer than threshold.
471469
postprocess_components: Post-process specific graph connected components ([0] for largest component only).
472470

scripts/la-vision/segment_sgns.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ def compute_components(mobie_dir, dataset_name):
4242
table_path = os.path.join(mobie_dir, dataset_name, "tables", SEG_NAME, "default.tsv")
4343
table = pd.read_csv(table_path, sep="\t")
4444
# This may need to be further adapted
45+
if "M04" in dataset_name:
46+
max_edge_distance = 70
47+
else:
48+
max_edge_distance = 30
49+
4550
table = label_components_sgn(table, min_size=100,
4651
threshold_erode=None,
47-
min_component_length=50,
48-
max_edge_distance=30,
49-
iterations_erode=None)
52+
min_component_length=1000,
53+
max_edge_distance=max_edge_distance,
54+
iterations_erode=0)
5055
table.to_csv(table_path, sep="\t", index=False)
5156

5257

0 commit comments

Comments
 (0)