Skip to content

Fix DVH calculation on boundary voxels and add regression test for final-bin volume#390

Open
SaharYaz wants to merge 2 commits into
dicompyler:masterfrom
SaharYaz:master
Open

Fix DVH calculation on boundary voxels and add regression test for final-bin volume#390
SaharYaz wants to merge 2 commits into
dicompyler:masterfrom
SaharYaz:master

Conversation

@SaharYaz

Copy link
Copy Markdown

Summary

This PR introduces a regression test that exposed an error in DVH histogram calculation when voxel centers lie exactly on structure boundaries. The fix adjusts the mask calculation and ensures correct handling of the final bin.

Changes

  • Test: Added test_histogram_preserves_final_bin to verify that a 1×1×1 dose grid slightly above an integer boundary yields:
    • 54 bins
    • final bin containing the full voxel volume (1 mm³ = 0.001 cc)
  • Fix: Updated dvhcalc to:
    • Expand polygons by a small tolerance before Path.contains_points so boundary voxels are treated as inside.
    • Fall back to PixelSpacing when LUT diffs are empty, enabling correct volume calculation on single-pixel grids.

Motivation

Without the fix, the regression test failed because the histogram collapsed to a single zero-volume bin. With this patch, the histogram correctly preserves the final bin volume.

Impact

  • Ensures accurate DVH calculation in edge cases with small or boundary-aligned structures.
  • Prevents zero-volume histograms in valid clinical scenarios.

Closes #389

Add a unit test constructing a 1×1×1 dose grid slightly above an integer
histogram boundary with a matching square contour. The test verifies that:

- the histogram has 54 bins
- the final bin contains the full voxel volume (1 mm³ = 0.001 cc)

Without mask tolerance, the calculation collapses to a one-bin, zero-volume
histogram, causing the test to fail.
* Expand polygons by a tiny radius before calling Path.contains_points so voxels on contour boundaries are treated as inside.
* Fall back to PixelSpacing when LUT diffs are empty, allowing volume calculation on single-pixel grids.
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.

DVH: Contours lying on dose-voxel edges produce “Empty DVH”

1 participant