Skip to content

add_body_envelope: add step-8 table detection to remove the CT table - #41

Merged
Can-Zhao merged 4 commits into
NVIDIA-Medtech:mainfrom
Can-Zhao:main
Jul 19, 2026
Merged

add_body_envelope: add step-8 table detection to remove the CT table#41
Can-Zhao merged 4 commits into
NVIDIA-Medtech:mainfrom
Can-Zhao:main

Conversation

@Can-Zhao

Copy link
Copy Markdown
Contributor

The find-air-invert steps can leak the air-density CT table into the body (air trapped between patient and table is a separate component from the exterior air, so it reads as "not air" -> body). Step 8 detects it as the largest connected component of body voxels that are actually air (CT < hu_threshold) and drops it when that component is >= table_frac_thresh (default 0.05) of the body. Since the seg labels the lungs, no legitimate air region is table-sized (a table is ~16-28% of body vs <0.3% clean).

Can-Zhao and others added 2 commits July 18, 2026 22:30
The find-air-invert steps can leak the air-density CT table into the body
(air trapped between patient and table is a separate component from the
exterior air, so it reads as "not air" -> body). Step 8 detects it as the
largest connected component of body voxels that are actually air
(CT < hu_threshold) and drops it when that component is >= table_frac_thresh
(default 0.05) of the body. Since the seg labels the lungs, no legitimate
air region is table-sized (a table is ~16-28% of body vs <0.3% clean).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…hu_threshold)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a step-8 "table detection" safety net to add_body_envelope in scripts/utils.py. When the find-air-invert pipeline leaks the CT table into the body mask (air trapped between patient and table is isolated from exterior air, so it reads as "not air" → body), step 8 identifies it as the largest connected component of body voxels with air-density HU and removes it when that component meets or exceeds table_frac_thresh (default 5%) of the total body.

  • Adds a single new parameter table_frac_thresh: float = 0.05 at the function signature, inserted before device — all visible callers use only the first two positional arguments, so there is no backward-compatibility break.
  • The detection logic correctly scopes to (out == body_label) & air_hu, so organ-labeled voxels (including lungs) are never candidates for removal; the fraction math (n_table / n_body) is computed before removal, which is the right baseline; and the print statement (previously flagged as missing observability) is now present and will surface in logs when the safety net fires.

Confidence Score: 5/5

Safe to merge — the change is a targeted safety net that only fires when a large air-density connected component is found inside the body mask, and it correctly scopes removal to unlabeled body voxels so organ labels are never touched.

The detection logic is well-bounded: it operates on (out == body_label) & air_hu, so labeled organ voxels (including lungs) can never be candidates for removal. The fraction comparison uses the pre-removal body count as the denominator, which is the correct baseline. All visible callers use only the first two positional arguments, so the new parameter causes no call-site breakage. The two concerns raised in the previous review round are both addressed.

No files require special attention.

Important Files Changed

Filename Overview
scripts/utils.py Adds step-8 table-detection safety net to add_body_envelope; logic, scoping, and fraction math are correct; previous review concerns (np.asarray wrap, observability print) are addressed.

Reviews (2): Last reviewed commit: "ruff format" | Re-trigger Greptile

Comment thread scripts/utils.py Outdated
Comment thread scripts/utils.py Outdated
Can-Zhao and others added 2 commits July 18, 2026 22:42
…eps 1&4) + log when table safety net fires

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Can-Zhao
Can-Zhao merged commit f2be2f0 into NVIDIA-Medtech:main Jul 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant