Skip to content

Update color_cvt.hpp, fix a potential overflow bug in Lab2BGR func #3113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2021

Conversation

TracelessLe
Copy link
Contributor

@TracelessLe TracelessLe commented Nov 18, 2021

fix a potential overflow bug in cv::cuda::cvtColor(cv::COLOR_Lab2BGR) func, which need to clamp on B/G/R.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Custom
buildworker:Custom=linux-4,linux-6
build_image:Custom=ubuntu-cuda:16.04
Xbuild_image:Custom=ubuntu-cuda:18.04

fix a potential overflow bug in cv::cuda::cvtColor(cv::COLOR_Lab2BGR) func, which need to clamp on B/G/R.
@alalek
Copy link
Member

alalek commented Nov 18, 2021

Did you run CUDA tests locally?

@TracelessLe
Copy link
Contributor Author

Did you run CUDA tests locally?

Sure, I did local tests in my project and using the "opencv/build/bin/opencv_test_cudaimgproc" executable file to verify both. This PR aims to fix the potential overflow bug in cv::cuda::cvtColor(cv::COLOR_Lab2BGR) function, which may cause some abnormal color if not clamp the float B/G/R value to range (0.0, 1.0).

The abnormal situation is such as attached below, where channel Green is overflow from float -0.0...1 (a very small negative number) to uint 255:
2021-11-19

2021-11-19 2

Some reference codes use cpu to do this color conversion are listed here.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you for contribution 👍

@opencv-pushbot opencv-pushbot merged commit ebcc69c into opencv:4.x Nov 28, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants