1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-27 06:13:05 +04:00
Files
Matt Van Horn 5e6a591357 Merge pull request #28873 from mvanhorn:osc/28429-fix-inter-nearest-exact-fp-5x
imgproc: fix INTER_NEAREST_EXACT to match Pillow (5.x retarget of #28661) #28873

## Summary

Fixes `INTER_NEAREST_EXACT` producing different results from Pillow for images with dimensions that are multiples of 64 (e.g., 128, 192).

Retargets #28661 to 5.x per core team request.

## Root cause

The old 16-bit fixed-point arithmetic (`ifx`, `ifx0`, `>> 16`) rounds differently from Pillow's pixel-center coordinate mapping. At exact pixel boundaries (e.g., y=7 with 128 to 160: `0.4 + 7*0.8 = 5.999999999999999`), Pillow's truncation drops to 5 while the old opencv formula rounds to 6.

## Changes

- `resize.cpp`: Replace `ifx/ifx0/ify/ify0` 16-bit fixed-point with an int64 arithmetic formula equivalent to `floor((i + 0.5) * src / dst)`, computed as `((int64_t)(i * 2 + 1) * src) / (dst * 2)`. This matches Pillow's pixel-center mapping exactly, is deterministic across platforms, and avoids FP rounding divergence entirely.
- `test_resize_bitexact.cpp`: Add `NearestExact_PillowCompat` covering 4 dimension pairs including the reproducer from #28429.

## Testing

- All 3 `Resize_Bitexact` tests pass (Linear8U, Nearest8U, NearestExact_PillowCompat) on this branch built against 5.x
- Verified bit-exact match to PIL output (Python 3.14, Pillow) on 49 dimension combinations including random pairs
- Built on macOS ARM64 with HAL (carotene/KleidiCV) active

Fixes #28429
2026-06-05 19:35:44 +03:00
..
2025-06-10 10:16:50 +03:00
2025-05-07 13:17:42 +03:00
2024-12-26 12:15:46 +00:00
2024-08-28 15:06:19 +03:00
2026-04-20 18:10:25 +02:00
2026-06-01 14:22:51 +03:00
2026-02-20 22:05:35 +03:00
2026-02-20 22:05:35 +03:00
2026-05-20 17:57:51 +03:00
2026-05-20 17:57:51 +03:00
2025-02-20 13:58:04 +03:00
2026-02-14 15:37:33 +03:00
2025-02-05 09:28:27 +03:00
2026-02-14 15:37:33 +03:00
2025-06-10 10:16:50 +03:00
2024-06-26 19:01:34 +03:00
2024-10-13 03:25:24 +03:00
2025-01-31 21:12:36 +05:30
2025-07-22 09:47:19 +03:00
2025-05-07 13:17:42 +03:00
2024-03-05 12:15:39 +03:00