Skip to content

🐛 Fix imresize Interpolation When Only output_size Is Given - #1173

Open
ww-6 wants to merge 1 commit into
TissueImageAnalytics:developfrom
ww-6:fix/imresize-output-size-interpolation
Open

ww-6 wants to merge 1 commit into
TissueImageAnalytics:developfrom
ww-6:fix/imresize-output-size-interpolation

Conversation

@ww-6

@ww-6 ww-6 commented Oct 22, 2026

Copy link
Copy Markdown
  • imresize documents scale_factor as output / input (scale_factor=0.5 halves the image), and the default interpolation="optimize" uses cv2.INTER_AREA below 1.0 and cv2.INTER_CUBIC otherwise.
  • When only output_size was passed, the scale factor was derived as input / output, so every downscale was treated as an upscale and got bicubic interpolation.
    • e.g. a 448 px image with output_size=(224, 224) used INTER_CUBIC, while scale_factor=0.5 on the same image used INTER_AREA.
  • Fix: derive the scale factor as output / input.
  • Add test_imresize_output_size_interpolation, which checks that output_size and the equivalent scale_factor select the same interpolation for both a downscale and an upscale. The test fails without the fix.

`imresize` documents `scale_factor` as output / input (e.g. 0.5 halves
the image), and the "optimize" interpolation picks `INTER_AREA` below
1.0 and `INTER_CUBIC` otherwise. When only `output_size` was passed, the
scale factor was derived as input / output, so every downscale was
treated as an upscale and got bicubic interpolation.

Derive the scale factor as output / input and add a regression test
checking that `output_size` and the equivalent `scale_factor` choose
the same interpolation.
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c0bbb14) to head (57b9de5).

Additional details and impacted files
@@             Coverage Diff              @@
##           develop     #1173      +/-   ##
============================================
+ Coverage    99.91%   100.00%   +0.08%     
============================================
  Files          112        15      -97     
  Lines        13454      1243   -12211     
  Branches      1610         0    -1610     
============================================
- Hits         13443      1243   -12200     
+ Misses           5         0       -5     
+ Partials         6         0       -6     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shaneahmed shaneahmed added the bug Something isn't working label Oct 23, 2026
@shaneahmed shaneahmed added this to the Release v2.1.4 milestone Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants