Skip to content

fix: preserve center crop size with odd padding - #746

Merged
joein merged 2 commits into
qdrant:mainfrom
HuaTNA:fix-center-crop-odd-padding
Sep 29, 2026
Merged

joein merged 2 commits into
qdrant:mainfrom
HuaTNA:fix-center-crop-odd-padding

Conversation

@HuaTNA

@HuaTNA HuaTNA commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Closes #745.

center_crop returns an undersized image when an input dimension needs an odd number of padding pixels: a 3×3 input cropped to 4×4 currently remains 3×3. With resizing disabled, this can leave differently sized images with inconsistent shapes and prevent OnnxImageModel from constructing its input batch.

Round the leading padding up so it offsets the floor-rounded crop origin. Add regression coverage for PIL and NumPy inputs, odd/even padding, mixed crop/pad axes, and pixel alignment against Pillow's crop result. Two preprocessing tests also cover batches with square and rectangular crop configurations.

Validation

  • Before the fix: the new center-crop tests produced 14 failures and 6 passes.
  • After the fix: pytest -q tests/test_image_transform.py tests/test_common.py tests/test_preprocessor_utils.py tests/test_postprocess.py — 68 passed.
  • Ruff lint/format hooks passed; package mypy passed with the CI flags; pyright tests/type_stub.py reported no errors or warnings.
  • Tested on Python 3.11.15, NumPy 2.4.6, Pillow 12.3.0, macOS arm64. The full model/GPU suite was not run. New regression tests require no model downloads.

All Submissions

AI assistance was used for investigation, implementation, and local test execution.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 17d33d83-5392-4434-ab74-2934b313d5d2

📥 Commits

Reviewing files that changed from the base of the PR and between 4de4023 and 199fbeb.

📒 Files selected for processing (1)
  • tests/test_image_transform.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

center_crop now rounds the top and left padding offsets up when padding an image to the requested crop size. A test checks pixel placement and confirms that processing 3×3 and 4×4 images together produces a batch shaped (2, 3, 4, 4).

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: serhiizghama

Merge Risk: ⚪ Minimal · up to 199fb

The padding correction and batch-shape regression test present no identified merge-blocking risk; merge after normal checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #745 requires the configured crop dimensions for padding on either or both axes, including mixed crop/pad cases. center_crop rounds leading padding up, and the remaining regression test verifi… Add regression tests for #745 covering NumPy inputs, even and one-axis padding, mixed crop/pad axes, and rectangular crop batches. Verify output dimensions and pixel alignment for each relevant case.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for center cropping with odd padding.
Description check ✅ Passed The description explains the center-crop issue, the fix, regression coverage, and validation results.
Out of Scope Changes check ✅ Passed The center_crop change and the remaining batch regression test both address the odd-padding and inconsistent-batch defect in issue #745. The reviewed changes contain no demonstrated unrelated work.
Full details: Linked Issues check

Explanation

Issue #745 requires the configured crop dimensions for padding on either or both axes, including mixed crop/pad cases. center_crop rounds leading padding up, and the remaining regression test verifies a PIL 3×3-to-4×4 batch case. The whole-PR diff does not include the stated coverage for NumPy inputs, even padding, one-axis padding, mixed crop/pad axes, or rectangular batch configurations. Those cases lack automated regression tests.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@joein
joein self-requested a review as a code owner September 29, 2026 09:52

@joein joein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for addressing this!

@joein
joein merged commit e0447a2 into qdrant:main Sep 29, 2026
12 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.

[Bug]: Center crop returns undersized images when padding is odd

2 participants