Choose a correlation resize factor rounded to an int

This commit is contained in:
jaknapper 2026-03-13 12:22:59 +00:00 committed by Joe Knapper
parent 9149121d4b
commit 96d67672d9
3 changed files with 46 additions and 3 deletions

View file

@ -431,3 +431,33 @@ def test_histo_workflow_settings_ui(histo_workflow, mocker):
"equal_distances",
]
assert names == expected_names
@pytest.mark.parametrize(
("save_res,expected_resize",)[
((1400, 1400), 1 / 2), # width=1400 -> N=2
((1640, 1232), 1 / 2), # width=1640 -> round(1640/750)=2
((760, 750), 1 / 1), # width=760 -> N=1
((1499, 1000), 1 / 2), # width ~1500 -> N=2
((2250, 1800), 1 / 3), # width=2250 -> N=3
((700, 700), 1 / 1), # width < 750 -> N=1
]
)
def test_correlation_resize(histo_workflow, save_res, expected_resize):
"""Test that scan_workflows chooses a suitable correlation_resize factor.
correlation_resize is always a unit fraction (1/N, N integer) so that the
downsampled image has an area roughly equal to TARGET_STITCHING_DIMENSION**2.
This ensures stitching correlations are fast, robust, and avoid artefacts.
The value is found by taking the image area (width * height), dividing by the
target area, taking the square root, and rounding to the nearest integer N. Then
correlation_resize = 1 / N.
"""
histo_workflow.save_resolution = save_res
histo_workflow.overlap = 0.1
settings = histo_workflow._get_stitching_settings_model()
assert isinstance(settings, StitchingSettings)
assert settings.correlation_resize == expected_resize
assert 0 < settings.correlation_resize <= 1