Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

Two bugs in affine transform decomposition were causing test failures: incorrect shear angle calculation (~50% of expected values) and crashes on reflection transforms.

Changes

src/clearex/registration/linear.py

  • _extract_shear(): Removed polar decomposition step and used direct RQ decomposition. Polar decomposition was splitting pure shear into rotation+stretch, producing incorrect angles (e.g., 12.53° instead of 26.57°).

  • _extract_rotation(): Added determinant check to detect reflection transforms (det < 0). Rotation.from_matrix() requires proper rotations (det = +1) and raises ValueError for reflections. Now reports zero rotation with warning instead of crashing.

tests/registration/test_image_registration.py

  • Updated tests to create temporary files with valid paths. ImageRegistration.__init__() requires fixed_image_path, moving_image_path, and save_directory as positional arguments and validates them immediately.

  • Fixed mock return values to match function signatures (tuples of 2 values).

  • Removed test_register_uses_provided_parameters which tested non-existent functionality (register() method takes no parameters).

Example

# Before: crashes on reflection
affine_matrix = np.diag([-1.0, 1.0, 1.0, 1.0])  # Reflection in X
inspect_affine_transform(transform)  # ValueError

# After: handles gracefully
inspect_affine_transform(transform)  
# Warning: Transform contains reflection (negative determinant).
# Rotation around X (roll) axis: 0.00 degrees
Original prompt

Please update/fix my tests...

FAILED tests/registration/test_image_registration.py::TestImageRegistration::test_initialization_with_defaults - TypeError: ImageRegistration.init() missing 3 required positional arguments: 'fixed_image_path', 'moving_image_path', and 'save_directory'
FAILED tests/registration/test_image_registration.py::TestImageRegistration::test_initialization_with_custom_values - FileNotFoundError: fixed.tif
FAILED tests/registration/test_image_registration.py::TestImageRegistration::test_register_missing_required_parameters - TypeError: ImageRegistration.init() missing 3 required positional arguments: 'fixed_image_path', 'moving_image_path', and 'save_directory'
FAILED tests/registration/test_image_registration.py::TestImageRegistration::test_register_uses_instance_attributes - ValueError: not enough values to unpack (expected 2, got 0)
FAILED tests/registration/test_image_registration.py::TestImageRegistration::test_register_uses_provided_parameters - PermissionError: [Errno 13] Permission denied: '/wrong'
FAILED tests/registration/test_linear.py::TestExtractShear::test_shear_xy - AssertionError: assert 'Shear angle XY: 26.57 degrees' in 'Shear angle XY: 12.53 degrees\nShear angle XZ: 0.00 degrees\nShear angle YZ: 0.00 degrees\n'

  • where 'Shear angle XY: 12.53 degrees\nShear angle XZ: 0.00 degrees\nShear angle YZ: 0.00 degrees\n' = CaptureResult(out='Shear angle XY: 12.53 degrees\nShear angle XZ: 0.00 degrees\nShear angle YZ: 0.00 degrees\n', err='').out
    FAILED tests/registration/test_linear.py::TestExtractShear::test_shear_xz - AssertionError: assert 'Shear angle XZ: 16.70 degrees' in 'Shear angle XY: 0.00 degrees\nShear angle XZ: 8.17 degrees\nShear angle YZ: -0.00 degrees\n'
  • where 'Shear angle XY: 0.00 degrees\nShear angle XZ: 8.17 degrees\nShear angle YZ: -0.00 degrees\n' = CaptureResult(out='Shear angle XY: 0.00 degrees\nShear angle XZ: 8.17 degrees\nShear angle YZ: -0.00 degrees\n', err='').out
    FAILED tests/registration/test_linear.py::TestExtractShear::test_shear_yz - AssertionError: assert 'Shear angle YZ: 21.80 degrees' in 'Shear angle XY: 0.00 degrees\nShear angle XZ: -0.00 degrees\nShear angle YZ: 10.49 degrees\n'
  • where 'Shear angle XY: 0.00 degrees\nShear angle XZ: -0.00 degrees\nShear angle YZ: 10.49 degrees\n' = CaptureResult(out='Shear angle XY: 0.00 degrees\nShear angle XZ: -0.00 degrees\nShear angle YZ: 10.49 degrees\n', err='').out
    FAILED tests/registration/test_linear.py::TestInspectAffineTransform::test_reflection_transform - ValueError: Non-positive determinant (left-handed or null coordinate frame) in rotation matrix 0: [[-1. 0. 0.]
    [ 0. 1. 0.]
    [ 0. 0. 1.]].

The user has attached the following files from their workspace:

  • src/clearex/visualization/napari.py
  • clearex

TITLE: Fixing Failed Test Suite for Image Registration Module

USER INTENT

Fix multiple failing tests in the image registration test suite, covering initialization, registration methods, shear angle calculations, and affine transform inspection.

TASK DESCRIPTION

The user needs to fix 9 failing tests across two test files:

  1. tests/registration/test_image_registration.py - 5 failures related to ImageRegistration class initialization and registration methods
  2. tests/registration/test_linear.py - 4 failures related to shear angle extraction and reflection transform handling

The failures involve:

  • Missing required positional arguments in ImageRegistration initialization
  • File path issues and permission errors
  • Incorrect shear angle calculations (actual values are approximately half of expected)
  • ValueError when handling reflection transforms with non-positive determinants

EXISTING

  • Test files exist at:
    • tests/registration/test_image_registration.py
    • tests/registration/test_linear.py
  • ImageRegistration class requires three positional arguments: fixed_image_path, moving_image_path, and save_directory
  • Shear angle extraction functionality exists but produces values approximately half of what tests expect
  • Affine transform inspection raises ValueError for reflection transforms with negative determinants

PENDING

  1. Fix ImageRegistration tests to properly initialize with required arguments (fixed_image_path, moving_image_path, save_directory)
  2. Fix file path and permission issues in registration tests
  3. Correct expected shear angle values in tests (divide by ~2 or fix calculation):
    • XY shear: expected 26.57°, actual 12.53°
    • XZ shear: expected 16.70°, actual 8.17°
    • YZ shear: expected 21.80°, actual 10.49°
  4. Handle reflection transforms (non-positive determinant) in affine transform inspection without raising ValueError

CODE STATE

tests/registration/test_image_registration.py

Issues:

  • Tests calling ImageRegistration() without required arguments
  • File paths like 'fixed.tif' not found
  • Permission error with '/wrong' path
  • ValueError about unpacking values in registration test

tests/registration/test_linea...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Fixed _extract_shear to use correct RQ decomposition output
- Fixed _extract_rotation to handle reflection transforms (negative determinant)
- Updated ImageRegistration tests to create valid temporary files
- Removed test for non-existent register() parameters
- All 39 tests now pass

Co-authored-by: AdvancedImagingUTSW <42547789+AdvancedImagingUTSW@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix image registration tests for initialization and parameters Fix shear extraction and reflection handling in affine transform decomposition Jan 2, 2026
@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.09%. Comparing base (a730f46) to head (ff55650).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
- Coverage   30.14%   29.09%   -1.05%     
==========================================
  Files          23       29       +6     
  Lines        1055     2093    +1038     
==========================================
+ Hits          318      609     +291     
- Misses        737     1484     +747     
Flag Coverage Δ
unittests 29.09% <100.00%> (-1.05%) ⬇️

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.

@AdvancedImagingUTSW AdvancedImagingUTSW marked this pull request as ready for review January 2, 2026 21:07
@AdvancedImagingUTSW AdvancedImagingUTSW merged commit 560d1a5 into main Jan 2, 2026
3 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.

2 participants