Skip to content

FIX: Converting mm to voxels wrong for dilation in registration#37

Merged
aylward merged 1 commit intoProject-MONAI:mainfrom
aylward:dilationbug
Mar 31, 2026
Merged

FIX: Converting mm to voxels wrong for dilation in registration#37
aylward merged 1 commit intoProject-MONAI:mainfrom
aylward:dilationbug

Conversation

@aylward
Copy link
Copy Markdown
Collaborator

@aylward aylward commented Mar 31, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Corrected mask dilation distance calculations in image registration to ensure proper spatial correspondence.

Copilot AI review requested due to automatic review settings March 31, 2026 23:00
@aylward aylward merged commit ad76a05 into Project-MONAI:main Mar 31, 2026
9 of 10 checks passed
@aylward aylward deleted the dilationbug branch March 31, 2026 23:00
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b255e19e-4628-4079-a914-819fba76ad4b

📥 Commits

Reviewing files that changed from the base of the PR and between 7e4a155 and 97238a4.

📒 Files selected for processing (1)
  • src/physiomotion4d/register_images_base.py

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


Walkthrough

The dilation radius computation in mask processing functions was corrected by inverting the ratio calculation. The formula now divides the requested dilation distance by voxel spacing, replacing the previous inverted ratio, affecting kernel size derivation in image registration workflows.

Changes

Cohort / File(s) Summary
Mask Dilation Radius Calculation
src/physiomotion4d/register_images_base.py
Corrected dilation radius computation in set_fixed_mask() and register() methods by inverting the ratio from image_spacing_x / mask_dilation_mm to mask_dilation_mm / image_spacing_x, affecting kernel size derivation in mask dilation operations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A ratio reversed, oh what a find!
Where dilation and spacing aligned,
From inverted to true, the masks now dilate,
Image registration—corrected, first-rate! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the mm→voxel conversion used for dilating registration masks so that a dilation specified in millimeters is converted to an appropriate voxel radius based on image spacing.

Changes:

  • Corrected mask dilation voxel-radius computation for the fixed mask.
  • Corrected mask dilation voxel-radius computation for the moving mask during registration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 187 to 191
if self.mask_dilation_mm > 0:
imMath = ttk.ImageMath.New(self.fixed_mask)
imMath.Dilate(
int(self.fixed_image.GetSpacing()[0] / self.mask_dilation_mm), 1, 0
int(self.mask_dilation_mm / self.fixed_image.GetSpacing()[0]), 1, 0
)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes a unit conversion that affects mask preprocessing across all registrars, but there are no tests asserting the mm→voxel dilation behavior (search in tests found no references to mask_dilation). Adding a focused unit test that checks the computed voxel radius for a known spacing would help prevent regressions.

Copilot uses AI. Check for mistakes.
Comment on lines 187 to 191
if self.mask_dilation_mm > 0:
imMath = ttk.ImageMath.New(self.fixed_mask)
imMath.Dilate(
int(self.fixed_image.GetSpacing()[0] / self.mask_dilation_mm), 1, 0
int(self.mask_dilation_mm / self.fixed_image.GetSpacing()[0]), 1, 0
)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: using int(mask_dilation_mm / spacing) floors the voxel radius, so the physical dilation will be <= the requested mm (sometimes noticeably, depending on spacing). If you want the closest physical match, consider using rounding/ceiling instead (and keep the approach consistent for fixed and moving masks).

Copilot uses AI. Check for mistakes.
Comment on lines 320 to 324
if self.mask_dilation_mm > 0:
imMath = ttk.ImageMath.New(new_moving_mask)
imMath.Dilate(
int(moving_image.GetSpacing()[0] / self.mask_dilation_mm), 1, 0
int(self.mask_dilation_mm / moving_image.GetSpacing()[0]), 1, 0
)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: int(mask_dilation_mm / spacing) floors the voxel radius, which can under-approximate the requested physical dilation. Consider rounding/ceiling if the intention is to match mm more closely.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@7e4a155). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #37   +/-   ##
=======================================
  Coverage        ?   13.67%           
=======================================
  Files           ?       49           
  Lines           ?     6596           
  Branches        ?        0           
=======================================
  Hits            ?      902           
  Misses          ?     5694           
  Partials        ?        0           
Flag Coverage Δ
integration-tests 13.67% <ø> (?)
unittests 13.67% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants