Spaces:
Sleeping
Sleeping
Upload centerline_extraction.py
Browse files- centerline_extraction.py +32 -8
centerline_extraction.py
CHANGED
|
@@ -1438,15 +1438,25 @@ def label_aorta_vs_arteries(segments, all_bifurcations, point_to_segments, preco
|
|
| 1438 |
else:
|
| 1439 |
n_keep = 1
|
| 1440 |
|
| 1441 |
-
# ββ
|
| 1442 |
-
# The gap analysis
|
| 1443 |
-
#
|
| 1444 |
# (e.g. trunk=10, ext=7, int=3 β gaps [3,4] β n_keep=2, WRONG).
|
| 1445 |
-
#
|
| 1446 |
-
#
|
| 1447 |
-
#
|
| 1448 |
-
#
|
| 1449 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1450 |
if n_keep > 1:
|
| 1451 |
r_conf_max = max(
|
| 1452 |
(r for c, r in aorta_ranked[:n_keep]
|
|
@@ -1454,6 +1464,7 @@ def label_aorta_vs_arteries(segments, all_bifurcations, point_to_segments, preco
|
|
| 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')
|
|
@@ -1462,6 +1473,19 @@ def label_aorta_vs_arteries(segments, all_bifurcations, point_to_segments, preco
|
|
| 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']]
|
|
|
|
| 1438 |
else:
|
| 1439 |
n_keep = 1
|
| 1440 |
|
| 1441 |
+
# ββ Guards against false aorta promotions at the iliac Y βββββββββββββ
|
| 1442 |
+
# The gap analysis alone mis-promotes an iliac leg when the
|
| 1443 |
+
# int-iliacβext-iliac gap is larger than the trunkβext-iliac gap
|
| 1444 |
# (e.g. trunk=10, ext=7, int=3 β gaps [3,4] β n_keep=2, WRONG).
|
| 1445 |
+
#
|
| 1446 |
+
# Two complementary guards are applied whenever a confirmed-aorta arm
|
| 1447 |
+
# is present in the top-n_keep group:
|
| 1448 |
+
#
|
| 1449 |
+
# Guard 1 β ratio check (same rule as the 2-arm branch):
|
| 1450 |
+
# Any non-confirmed arm being kept must be β₯ AORTA_CONTINUATION_RATIO
|
| 1451 |
+
# of the confirmed arm's radius. Catches ext-iliac < 75 % of trunk.
|
| 1452 |
+
#
|
| 1453 |
+
# Guard 2 β symmetric-branch check (3-arm junctions only):
|
| 1454 |
+
# At the iliac Y the two iliac arms are proportionally closer to each
|
| 1455 |
+
# other than either is to the trunk: r3/r2 > r2/r1.
|
| 1456 |
+
# Triggers when guard 1 just misses (ext β 75β80 % of trunk) but the
|
| 1457 |
+
# two branches are still noticeably more similar to each other than to
|
| 1458 |
+
# the trunk. False-positive risk is low for realistic anatomy because
|
| 1459 |
+
# celiac/renal junctions have r3 << r2 so r3/r2 βͺ r2/r1.
|
| 1460 |
if n_keep > 1:
|
| 1461 |
r_conf_max = max(
|
| 1462 |
(r for c, r in aorta_ranked[:n_keep]
|
|
|
|
| 1464 |
default=0,
|
| 1465 |
)
|
| 1466 |
if r_conf_max > 0:
|
| 1467 |
+
# Guard 1: ratio threshold
|
| 1468 |
for i in range(n_keep - 1, 0, -1):
|
| 1469 |
c_i, r_i = aorta_ranked[i]
|
| 1470 |
if (not segments[c_i['seg_idx']].get('confirmed_aorta')
|
|
|
|
| 1473 |
break
|
| 1474 |
n_keep = max(1, n_keep)
|
| 1475 |
|
| 1476 |
+
# Guard 2: symmetric-branch check (3-arm only)
|
| 1477 |
+
# Only applied when guard 1 left n_keep=2 (didn't fire above).
|
| 1478 |
+
if n_keep == 2 and len(aorta_ranked) == 3:
|
| 1479 |
+
ra = aorta_ranked[0][1]
|
| 1480 |
+
conn2, rb = aorta_ranked[1]
|
| 1481 |
+
rc = aorta_ranked[2][1]
|
| 1482 |
+
# r3/r2 > r2/r1 ββ two thinner arms more similar to each
|
| 1483 |
+
# other than to the thickest β thickest is the lone trunk.
|
| 1484 |
+
if (rb > 0 and ra > 0
|
| 1485 |
+
and (rc / rb) > (rb / ra)
|
| 1486 |
+
and not segments[conn2['seg_idx']].get('confirmed_aorta')):
|
| 1487 |
+
n_keep = 1
|
| 1488 |
+
|
| 1489 |
# ββ Apply labels ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1490 |
for i, (c, avg_r) in enumerate(aorta_ranked):
|
| 1491 |
seg = segments[c['seg_idx']]
|