← Back to Pull requests

Fix xvr principal-point sign and DeepFluoro voxel origin #1

Closed
unknown closed this pull request without merging on Oct 05, 2026 22:21 UTC
View on GitHub
unknown unknown commented on Oct 05, 2026 19:29 UTC
Author

Fixes the two geometry offsets behind the paired comparison: the Ljubljana horizontal offset that PR #73's offset-sign diagnostic exposed, and a smaller half-voxel offset in DeepFluoro. With both, Ljubljana's renders move onto their angiograms and DeepFluoro's structural agreement rises above the published numbers.

Results

All 382 views, rerun locally with the PR #73 protocol (render_and_compare.py, same data revision and settings). Medians of per-subject medians:

| | DeepFluoro gradient NCC | DeepFluoro NCC | Ljubljana gradient NCC | Ljubljana NCC | Ljubljana matched beats misposed |
|---|---:|---:|---:|---:|---:|
| PR #73 as published | 0.623 | 0.936 | 0.219 | 0.253 | 15/20 |
| Principal point only | 0.598 | 0.935 | 0.737 | 0.840 | 20/20 |
| This PR | 0.681 | 0.939 | 0.737 | 0.840 | 20/20 |

DeepFluoro still has 362/362 matched views beating their misposed controls. Residual misalignment (edge-based phase correlation, binned pixels) falls from 0.94 to 0.19 px RMS on DeepFluoro and from up to 92 px to 0.26 px RMS on Ljubljana, with no systematic shift left in either.

1. Detector geometry is set by its principal point

CarmGeometry.detector_offset_xy_mm described how far the detector is displaced, which is the opposite of what calibrations store (where the perpendicular ray lands), so every adapter had to negate it. It is replaced by principal_point_px: the (column, row) pixel hit by the ray perpendicular to the detector, in the coordinates project_point_to_detector returns. None means the image centre. The renderer's mm offset is derived from it in one place; the shader is unchanged. detector_offset_xy_mm was added in this PR stack and is not on main.

The xvr adapter passed (x0, -y0), which mirrors the principal point horizontally. The stored x0/y0 are principal-point offsets from the image centre along columns and rows. xvr itself negates x0 (only) before building DiffDRR's detector (xvr 4c68e0c, "Fix x0 principle point sign"). In DiffDRR 0.6.0 the detector grid reverses the row axis but not the column axis before adding the constructor offsets, so the raw stored values come out right in Y and mirrored in X. DiffDRR's own intrinsic matrix also disagrees with its renderer in Y. The adapter's DiffDRR agreement check passed because it fed DiffDRR the stored x0 without xvr's negation.

Measured on the 20 Ljubljana views before the fix, the horizontal render shift equals 2·x0/pitch (slope 0.998, r = 1.000, offsets −28 to +15 mm), and no vertical shift appears even where a y0 sign error would give 11–13 px. DeepFluoro's offsets are half a native pixel (−0.097 mm), so they cannot distinguish the signs.

2. DeepFluoro voxels sit where the xvr poses expect them

After fix 1, every DeepFluoro subject still sat about one binned pixel off its references, in the same direction for all six subjects. Fitting a constant 3D volume shift to the per-view residuals explains them better than a constant detector shift (0.22 vs 0.30 px RMS, from 0.94), giving +0.53/+0.46/+0.50 voxels along i/j/k (1 mm voxels). The DeepFluoro poses in this release therefore treat NIfTI indices as voxel corners, as DiffDRR does with voxel_shift=0, which xvr's registration uses. Ljubljana's poses expect voxel centres: the same half-voxel shift worsens all 20 Ljubljana views.

POSE_VOXEL_ORIGIN = {"deepfluoro": "corner", "ljubljana": "center"} records this. XvrView.camera applies it by offsetting the camera, because the renderer positions the C-arm relative to the volume centre, so moving the volume origin alone has no effect. XvrCamera.project applies the same offset, keeping fiducial projections consistent with renders. This is a property of the data release, not of the simulator: #72's voxel-centre fix concerns from_dicom/from_nifti and does not change this path (I checked a #72 + #73 merge: renders identical to 1e-5).

Tests

  • The "independent" pinhole-matrix test had the wrong sign built in; it now uses cx = (W-1)/2 + x0/dx.

  • New: the perpendicular ray lands on principal_point_px for centred and off-centre principal points.

  • New: each voxel-origin convention renders specific voxels where the pose frame places them.

  • The GPU bead test uses an off-centre principal point.

  • New data tests (gpu/slow, skipped unless XVR_DATA_ROOT points to an xvr-data download): all 20 Ljubljana views must align within one binned pixel, and the median offset of eight views per DeepFluoro subject must stay below half a binned pixel. Against the previous adapter, all 10 Ljubljana and all 6 DeepFluoro subjects fail; with this PR all pass.

  • 285 tests pass locally, including GPU and data tests; pre-commit is clean. CI runs the CPU tests.
  • Report

    docs/reports/deepfluoro-ljubljana/ is regenerated from a clean run at 9ebb85e (the numbers in the table above). Its README adds a "Changes since the previous report" section with the before/after table and both conventions. The offset-sign diagnostic is removed from render_and_compare.py and build_local_report.py, since it would now render the old mirrored geometry. Patient and generated images remain local, as before.

    Upstream follow-ups

  • Report DiffDRR's Y-axis intrinsic/renderer mismatch.

  • Confirm the DeepFluoro voxel convention with the xvr author.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: cdinea Review duration: 172m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%