Spaces:
Sleeping
Sleeping
Upload centerline_extraction.py
Browse files- centerline_extraction.py +30 -5
centerline_extraction.py
CHANGED
|
@@ -1438,6 +1438,30 @@ def label_aorta_vs_arteries(segments, all_bifurcations, point_to_segments, preco
|
|
| 1438 |
else:
|
| 1439 |
n_keep = 1
|
| 1440 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1441 |
# ββ Apply labels ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1442 |
for i, (c, avg_r) in enumerate(aorta_ranked):
|
| 1443 |
seg = segments[c['seg_idx']]
|
|
@@ -1493,16 +1517,17 @@ def label_aorta_vs_arteries(segments, all_bifurcations, point_to_segments, preco
|
|
| 1493 |
|
| 1494 |
# ββ Step 4: Detect iliac cutoff from labeled topology βββββββββββββββββββββ
|
| 1495 |
# Strategy: after full labeling, the iliac cutoff is the lowest-Z validated
|
| 1496 |
-
# junction that
|
| 1497 |
-
#
|
| 1498 |
-
#
|
|
|
|
|
|
|
| 1499 |
iliac_cutoff = None
|
| 1500 |
cutoff_candidates = []
|
| 1501 |
for bif_id, (bif, connections) in valid_bifs.items():
|
| 1502 |
seg_indices = [c['seg_idx'] for c in connections]
|
| 1503 |
has_confirmed_aorta = any(segments[si].get('confirmed_aorta') for si in seg_indices)
|
| 1504 |
-
|
| 1505 |
-
if has_confirmed_aorta and has_artery:
|
| 1506 |
cutoff_candidates.append(bif)
|
| 1507 |
|
| 1508 |
if cutoff_candidates:
|
|
|
|
| 1438 |
else:
|
| 1439 |
n_keep = 1
|
| 1440 |
|
| 1441 |
+
# ββ Guard: confirmed-aorta threshold check βββββββββββββββββββββββββββ
|
| 1442 |
+
# The gap analysis (3+ arms) can mis-promote an iliac leg to
|
| 1443 |
+
# confirmed_aorta when the ext-iliacβint-iliac gap > trunkβext-iliac gap
|
| 1444 |
+
# (e.g. trunk=10, ext=7, int=3 β gaps [3,4] β n_keep=2, WRONG).
|
| 1445 |
+
# Fix: if any confirmed arm is among the top-n_keep group, every
|
| 1446 |
+
# non-confirmed arm we would keep must still satisfy the ratio check
|
| 1447 |
+
# relative to the confirmed arm's radius β the same guard used for 2-arm
|
| 1448 |
+
# junctions. This correctly reduces n_keep to 1 at the iliac Y while
|
| 1449 |
+
# leaving legitimate aorta-to-aorta continuations (ratio β₯ 0.75) intact.
|
| 1450 |
+
if n_keep > 1:
|
| 1451 |
+
r_conf_max = max(
|
| 1452 |
+
(r for c, r in aorta_ranked[:n_keep]
|
| 1453 |
+
if segments[c['seg_idx']].get('confirmed_aorta')),
|
| 1454 |
+
default=0,
|
| 1455 |
+
)
|
| 1456 |
+
if r_conf_max > 0:
|
| 1457 |
+
for i in range(n_keep - 1, 0, -1):
|
| 1458 |
+
c_i, r_i = aorta_ranked[i]
|
| 1459 |
+
if (not segments[c_i['seg_idx']].get('confirmed_aorta')
|
| 1460 |
+
and r_i < AORTA_CONTINUATION_RATIO * r_conf_max):
|
| 1461 |
+
n_keep = i
|
| 1462 |
+
break
|
| 1463 |
+
n_keep = max(1, n_keep)
|
| 1464 |
+
|
| 1465 |
# ββ Apply labels ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1466 |
for i, (c, avg_r) in enumerate(aorta_ranked):
|
| 1467 |
seg = segments[c['seg_idx']]
|
|
|
|
| 1517 |
|
| 1518 |
# ββ Step 4: Detect iliac cutoff from labeled topology βββββββββββββββββββββ
|
| 1519 |
# Strategy: after full labeling, the iliac cutoff is the lowest-Z validated
|
| 1520 |
+
# junction that touches at least one confirmed-Aorta arm. The main trunk has
|
| 1521 |
+
# confirmed_aorta=True; its terminal junction (the iliac Y) is the most
|
| 1522 |
+
# caudal such junction. We intentionally do NOT require an Artery arm here β
|
| 1523 |
+
# if both iliac legs were mislabeled Aorta by BFS, has_artery would be False
|
| 1524 |
+
# and we'd fall through to a higher (wrong) junction.
|
| 1525 |
iliac_cutoff = None
|
| 1526 |
cutoff_candidates = []
|
| 1527 |
for bif_id, (bif, connections) in valid_bifs.items():
|
| 1528 |
seg_indices = [c['seg_idx'] for c in connections]
|
| 1529 |
has_confirmed_aorta = any(segments[si].get('confirmed_aorta') for si in seg_indices)
|
| 1530 |
+
if has_confirmed_aorta:
|
|
|
|
| 1531 |
cutoff_candidates.append(bif)
|
| 1532 |
|
| 1533 |
if cutoff_candidates:
|