Skip to content

Align center cropping with centered padding for odd size differences - #134

Open
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/center-crop-parity-alignment-20261006
Open

sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:masterfrom
sylvesterkaczmarek:fix/center-crop-parity-alignment-20261006

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #133.

Compute crop offsets from half the size difference rather than subtracting two separately rounded centers. This preserves the bottom/right convention already used by centered padding and prevents a padding/cropping round trip from discarding source pixels. Updated the docstring to specify which side loses the extra pixel. Channel layouts, batch handling and oversized-target behavior are unchanged.

Validation

python -m pytest -q dm_pix/_src/augment_test.py

Current rebased head: 31 crop-alignment regressions and 78 adjacent augmentation tests passed. The earlier full augmentation run passed 883 tests. Seventeen new cases fail on unchanged upstream; fourteen controls pass. References include direct integer-margin slices and TensorFlow crop-or-pad output. Eager/JIT results, multiple layouts, round-trip pixel identity and gradients are covered. The independent Gaussian-blur PRs are untouched.

Tested locally on macOS CPU using real module imports. New-test formatting, scoped static checks, syntax checks and git diff --check pass. No dependency or workflow changes. The full repository suite was not run.

Comment thread dm_pix/_src/crop_alignment_test.py Outdated
import tensorflow as tf


class CropAlignmentTest(parameterized.TestCase):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this tests under dm_pix/_src/augment_test.py.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to augment_test.py. The 31 new cases and 78 adjacent tests pass on current master.

@sylvesterkaczmarek
sylvesterkaczmarek force-pushed the fix/center-crop-parity-alignment-20261006 branch from b29a93a to 80ca824 Compare October 19, 2026 15:50

@claudiofantacci claudiofantacci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@claudiofantacci claudiofantacci added the enhancement New feature or request label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Center cropping shifts images after odd-sized centered padding

3 participants