Skip to content

Feature/nightly#74

Closed
aylward wants to merge 3 commits into
Project-MONAI:mainfrom
aylward:feature/nightly
Closed

Feature/nightly#74
aylward wants to merge 3 commits into
Project-MONAI:mainfrom
aylward:feature/nightly

Conversation

@aylward

@aylward aylward commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added new image-processing capabilities for dilation, erosion, and keeping the largest connected component.
    • Improved several segmentation and registration workflows to use the updated image tools.
  • Bug Fixes

    • Made Windows nightly setup more robust by using the system Python launcher.
    • Updated branch-trimming tests to run without older Python-specific skips.
  • Documentation

    • Updated dependency lists and installation docs to reflect the current medical imaging stack.

aylward added 3 commits July 3, 2026 10:41
Add three new ImageTools methods that cover all TubeTK usage in the
package and experiments:

- make_isotropic_image: already existed (equivalent to
  ResampleImage.SetMakeHighResIso); now used in experiments too.
- binary_dilate_image: replaces ImageMath.Dilate + GetOutputUChar/Short,
  using BinaryDilateImageFilter with a FlatStructuringElement ball kernel.
- binary_erode_image: replaces ImageMath.Erode,
  using BinaryErodeImageFilter with a FlatStructuringElement ball kernel.
- keep_largest_connected_component: replaces SegmentConnectedComponents
  with SetKeepOnlyLargestComponent(True), using ConnectedComponentImageFilter
  + RelabelComponentImageFilter + BinaryThresholdImageFilter.

Callers updated:
- src/physiomotion4d/segment_anatomy_base.py: hole-fill open in
  segment_connected_component() now uses ImageTools methods.
- src/physiomotion4d/segment_heart_simpleware.py: myocardium dilate/erode
  in segmentation_method() now uses ImageTools methods.
- src/physiomotion4d/segment_heart_simpleware_trimmed_branches.py:
  trim_branches() rewrites the multi-label ImageMath chain as per-label
  binary masks (avoiding inter-label bleed) and uses ImageTools for all
  morphology and largest-component selection.
- experiments/Heart-Statistical_Model_To_Patient/*.py: ResampleImage
  replaced by ImageTools().make_isotropic_image().
- experiments/Lung-GatedCT_To_USD/0-register_dirlab_4dct.py: dilate_mask()
  helper replaced by ImageTools().binary_dilate_image().

Non-code changes:
- pyproject.toml: drop itk-tubetk>=1.4.0 dependency.
- docs/conf.py: remove sys.modules['itk.TubeTK'] mock (no longer imported).
- tests/test_segment_heart_simpleware_trimmed_branches.py: remove the
  Python <3.12 skipif guard that existed solely because TubeTK's
  SegmentConnectedComponents segfaulted on CPython 3.11; trim_branches()
  is now pure ITK and runs on all supported Python versions.
Copilot AI review requested due to automatic review settings July 3, 2026 15:31
@aylward aylward closed this Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6ecea8df-c6f0-4c09-a02b-bab77b7b5bf8

📥 Commits

Reviewing files that changed from the base of the PR and between f19c8dd and 12a7344.

📒 Files selected for processing (15)
  • .github/workflows/nightly-health.yml
  • README.md
  • docs/conf.py
  • docs/installation.rst
  • experiments/Heart-Statistical_Model_To_Patient/heart_model_to_model_icp_itk.py
  • experiments/Heart-Statistical_Model_To_Patient/heart_model_to_model_registration_pca.py
  • experiments/Lung-GatedCT_To_USD/0-register_dirlab_4dct.py
  • pyproject.toml
  • src/physiomotion4d/image_tools.py
  • src/physiomotion4d/register_images_icon.py
  • src/physiomotion4d/segment_anatomy_base.py
  • src/physiomotion4d/segment_heart_simpleware.py
  • src/physiomotion4d/segment_heart_simpleware_trimmed_branches.py
  • statistics.md
  • tests/test_segment_heart_simpleware_trimmed_branches.py

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


Walkthrough

This PR removes the itk-tubetk dependency across the project, replacing TubeTK-based resampling, dilation, erosion, and connected-component operations with new ImageTools methods (binary_dilate_image, binary_erode_image, keep_largest_connected_component). Documentation, dependency lists, and a test's TubeTK-related skip guards are updated accordingly. An unrelated CI venv launcher fix is also included.

Changes

TubeTK removal and ImageTools migration

Layer / File(s) Summary
New ImageTools morphology methods
src/physiomotion4d/image_tools.py
Adds binary_dilate_image, binary_erode_image, and keep_largest_connected_component methods using ITK filters, and trims a TubeTK reference from a docstring.
Segmentation modules migrated to ImageTools
src/physiomotion4d/segment_anatomy_base.py, segment_heart_simpleware.py, segment_heart_simpleware_trimmed_branches.py
Replaces TubeTK ImageMath-based dilation/erosion and connected-component logic with new ImageTools calls across hole-filling, exterior mask generation, and branch trimming.
Experiment scripts migrated to ImageTools
experiments/Heart-Statistical_Model_To_Patient/*.py, experiments/Lung-GatedCT_To_USD/0-register_dirlab_4dct.py
Replaces TubeTK-based isotropic resampling and mask dilation with ImageTools.make_isotropic_image and ImageTools.binary_dilate_image.
Dependency removal and documentation updates
pyproject.toml, docs/conf.py, README.md, docs/installation.rst, statistics.md, src/physiomotion4d/register_images_icon.py, .github/workflows/nightly-health.yml
Removes itk-tubetk dependency and its Sphinx mock, removes TubeTK from dependency lists in docs, trims an unrelated docstring, and switches the Windows CI venv command to use py -m venv.
Test updates removing TubeTK segfault guards
tests/test_segment_heart_simpleware_trimmed_branches.py
Removes Python-version-based TubeTK segfault skip logic and updates docstrings to reflect standard ITK filter usage.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

✨ 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.

@aylward aylward deleted the feature/nightly branch July 3, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the project’s dependency on TubeTK by replacing TubeTK-based image morphology / connected-component operations with standard ITK filters (via ImageTools), and updates tests/docs/workflows accordingly.

Changes:

  • Drop itk-tubetk from dependencies and remove remaining TubeTK usages in segmentation and experiments.
  • Add standard-ITK implementations for binary dilate/erode and “keep largest connected component” to ImageTools, and refactor heart segmentation trimming logic to use them.
  • Update docs/tests and adjust the nightly workflow’s venv creation command.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_segment_heart_simpleware_trimmed_branches.py Removes Python-version gating now that trimming no longer depends on TubeTK.
statistics.md Removes TubeTK from the dependency list.
src/physiomotion4d/segment_heart_simpleware.py Replaces TubeTK ImageMath dilation/erosion with ImageTools helpers.
src/physiomotion4d/segment_heart_simpleware_trimmed_branches.py Refactors trim_branches() to use ITK-only morphology and connected-component filtering.
src/physiomotion4d/segment_anatomy_base.py Replaces TubeTK morphology usage with ImageTools.
src/physiomotion4d/register_images_icon.py Updates a comment that previously referenced TubeTK behavior.
src/physiomotion4d/image_tools.py Adds ITK-only binary dilate/erode and largest-component utilities.
README.md Removes TubeTK from “Key Dependencies”.
pyproject.toml Removes itk-tubetk from install requirements.
experiments/Lung-GatedCT_To_USD/0-register_dirlab_4dct.py Uses ImageTools for mask dilation instead of TubeTK.
experiments/Heart-Statistical_Model_To_Patient/heart_model_to_model_registration_pca.py Uses ImageTools.make_isotropic_image() instead of TubeTK resampling.
experiments/Heart-Statistical_Model_To_Patient/heart_model_to_model_icp_itk.py Uses ImageTools.make_isotropic_image() instead of TubeTK resampling.
docs/installation.rst Removes TubeTK from documented dependencies.
docs/conf.py Removes Sphinx mocking of itk.TubeTK.
.github/workflows/nightly-health.yml Changes venv creation command (needs pinning to Python 3.11).

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

Comment on lines +307 to +311
imMath = ImageTools()
spacing = interior_image.GetSpacing()
imMath.Dilate(round(7 / spacing[0]), 1, 0)
imMath.Erode(round(4 / spacing[0]), 1, 0)
exterior_image = imMath.GetOutputUChar()
exterior_image = imMath.binary_dilate_image(
interior_image, round(7 / spacing[0]), 1, 0
)
imMath.SetInput(lv_img)
imMath.Dilate(round(2 / spacing[0]), 1, 0)
lv_img = imMath.GetOutput()
lv_img = image_tools.binary_dilate_image(lv_img, round(2 / spacing[0]), 1, 0)
Comment on lines 58 to 62
# Python 3.11 is required because the [physicsnemo] extra pulls in
# nvidia-physicsnemo, which requires Python >= 3.11.
run: |
& "C:\Users\saylward\AppData\Local\Programs\Python\Python311\python.exe" -m venv "$env:RUNNER_TEMP\physiomotion4d-venv"
& py -m venv "$env:RUNNER_TEMP\physiomotion4d-venv"
echo "$env:RUNNER_TEMP\physiomotion4d-venv\Scripts" >> $env:GITHUB_PATH
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.76923% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 35.93%. Comparing base (f19c8dd) to head (12a7344).

Files with missing lines Patch % Lines
src/physiomotion4d/segment_anatomy_base.py 25.00% 3 Missing ⚠️
src/physiomotion4d/segment_heart_simpleware.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
+ Coverage   34.66%   35.93%   +1.26%     
==========================================
  Files          57       57              
  Lines        7283     7289       +6     
==========================================
+ Hits         2525     2619      +94     
+ Misses       4758     4670      -88     
Flag Coverage Δ
unittests 35.93% <90.76%> (+1.26%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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