[cudawarping] Add align_corners option to cv::cuda::resize - #4181
Open
zhangnju wants to merge 1 commit into
Open
[cudawarping] Add align_corners option to cv::cuda::resize#4181zhangnju wants to merge 1 commit into
zhangnju wants to merge 1 commit into
Conversation
cv::cuda::resize's INTER_LINEAR uses the scale mapping src = dst*srcSize/dstSize and rounds to nearest. Add an optional align_corners flag (INTER_LINEAR only) that instead maps src = dst*(srcSize-1)/(dstSize-1) and truncates toward zero, matching PyTorch's interpolate(align_corners=True) and reference integer bilinear used by ML image preprocessors (e.g. Qwen-VL). Verified element-wise (max abs diff 1/255, zero elements off by more than a quantum) against the CPU reference. Implemented via a new truncating-linear kernel selected through an internal interpolation sentinel; the default path and public enum are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cv::cuda::resizewithINTER_LINEARcurrently uses the scale mappingsrc = dst * srcSize/dstSizeand rounds the interpolated value to nearest. This PR adds an optionalalign_cornersflag (INTER_LINEAR only) that instead mapssrc = dst * (srcSize-1)/(dstSize-1)and truncates toward zero.This matches PyTorch's
interpolate(mode="bilinear", align_corners=True)and the reference integer bilinear used by several ML image preprocessors (e.g. Qwen-VL), which is useful when a GPU preprocessing path must be numerically consistent with a CPU/reference pipeline.Details
bool align_corners = falseparameter oncv::cuda::resize(default keeps existing behaviour; publicInterpolationFlagsenum unchanged).resize_linear_trunc, selected through an internal interpolation sentinel; the default INTER_LINEAR path is untouched.Pull Request Readiness Checklist