Fix shear extraction and reflection handling in affine transform decomposition #7
+85
−65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 raisesValueErrorfor reflections. Now reports zero rotation with warning instead of crashing.tests/registration/test_image_registration.pyUpdated tests to create temporary files with valid paths.
ImageRegistration.__init__()requiresfixed_image_path,moving_image_path, andsave_directoryas positional arguments and validates them immediately.Fixed mock return values to match function signatures (tuples of 2 values).
Removed
test_register_uses_provided_parameterswhich tested non-existent functionality (register()method takes no parameters).Example
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'
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'
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'
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:
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:
tests/registration/test_image_registration.py- 5 failures related to ImageRegistration class initialization and registration methodstests/registration/test_linear.py- 4 failures related to shear angle extraction and reflection transform handlingThe failures involve:
EXISTING
tests/registration/test_image_registration.pytests/registration/test_linear.pyfixed_image_path,moving_image_path, andsave_directoryPENDING
CODE STATE
tests/registration/test_image_registration.py
Issues:
ImageRegistration()without required argumentstests/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.