Skip to content

bit-exact cuda::equalizeHist#18136

Merged
opencv-pushbot merged 2 commits intoopencv:3.4from
nglee:dev_cudaEqualizeHistBitExact
Aug 26, 2020
Merged

bit-exact cuda::equalizeHist#18136
opencv-pushbot merged 2 commits intoopencv:3.4from
nglee:dev_cudaEqualizeHistBitExact

Conversation

@nglee
Copy link
Copy Markdown
Contributor

@nglee nglee commented Aug 19, 2020

Merge with extra: opencv/opencv_extra#797

This PR aims to make the cuda::equalizeHist bit-exact to the CPU counterpart.

resolves #18035
resolves #10330

When building a lookup table from a histogram, the CPU implementation does this:
(from #226 (comment))

C = count(Y == min(Y))
lut[i] = 255 * (count(Y <= i) - C) / (width * height - C)

However, what the CUDA implementation did was this:

lut[i] = 255 * count(Y <= i - 1) / (width * height)

This PR implements a CUDA kernel to make the CUDA implementation bit-exact.

For tests, now we can change this:

    EXPECT_MAT_NEAR(dst_gold, dst, 3.0);

to this:

    EXPECT_MAT_NEAR(dst_gold, dst, 0.0);
                                   ^^^

The performance of new CUDA implementation is similar to the previous one, and faster than the CPU implementation.

Image size CPU CUDA(old) CUDA(new,bit-exact)
1280x720 0.21 0.11 0.12
1280x1024 0.30 0.12 0.12
1920x1080 0.46 0.47 0.44
2048x2048 0.89 0.54 0.46
4096x3072 2.84 0.78 0.57

Tested on RTX 2080 Ti and CUDA 11.


  • 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
allow_multiple_commits=1
opencv_extra=dev_cudaEqualizeHistBitExact
force_builders=Custom
buildworker:Custom=linux-4
build_image:Custom=ubuntu-cuda:16.04

@asmorkalov asmorkalov added the category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib label Aug 19, 2020
@asmorkalov asmorkalov self-requested a review August 19, 2020 18:00
@asmorkalov
Copy link
Copy Markdown
Contributor

@nglee Good Job! I'll test the solution for older cards and return back.

@nglee
Copy link
Copy Markdown
Contributor Author

nglee commented Aug 20, 2020

We also need the following PR to pass performance tests:
opencv/opencv_extra#797

@asmorkalov
Copy link
Copy Markdown
Contributor

Hello @nglee Please take a look on CI status, there is build failure on configuration Ubuntu 14.04 + CUDA:

CMakeFiles/opencv_test_cudafilters.dir/test/test_filters.cpp.o -c /build/precommit_custom_linux/3.4/opencv/modules/cudafilters/test/test_filters.cpp
/build/precommit_custom_linux/3.4/opencv/modules/cudaimgproc/test/test_histogram.cpp: In member function 'virtual void opencv_test::{anonymous}::EqualizeHistIssue_Issue18035_Test::Body()':
/build/precommit_custom_linux/3.4/opencv/modules/cudaimgproc/test/test_histogram.cpp:244:5: error: in C++98 'imgPaths' must be initialized by constructor, not by '{...}'
     };

I see the same on my Jetson TK1. It's rootfs is based on Ubuntu 14.04 too.

Also you need to update performance test regression data to make the test pass performance test. Follow this instruction to do it: https://github.com/opencv/opencv/wiki/HowToUsePerfTests#how-to-update-perf-data

@asmorkalov
Copy link
Copy Markdown
Contributor

@nglee I updated CI instructions to take your test data patch in account. It should be handled by CI bot automatically. Please take a look on the build issue.

@nglee nglee force-pushed the dev_cudaEqualizeHistBitExact branch from 115fcf3 to f617f18 Compare August 21, 2020 14:11
@nglee
Copy link
Copy Markdown
Contributor Author

nglee commented Aug 21, 2020

@asmorkalov I've fixed the build error, and also some compiler warnings.

@alalek
Copy link
Copy Markdown
Member

alalek commented Aug 21, 2020

updated CI instructions to take your test data patch in account

It should be handled automatically on Public CI without extra instructions (it checks branch with the same name in opencv_extra)
Need to just trigger new builds to pull patch from opencv_extra (force push "amended" commit into the main PR)

Copy link
Copy Markdown
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 👍

@opencv-pushbot opencv-pushbot merged commit 01324b0 into opencv:3.4 Aug 26, 2020
@rgov
Copy link
Copy Markdown

rgov commented Aug 26, 2020

Great to see this in, thanks very much @nglee.

Can someone please provide an estimate on when this would be merged into the master branch? Is that done weekly or something?

This was referenced Aug 26, 2020
@nglee nglee deleted the dev_cudaEqualizeHistBitExact branch August 27, 2020 01:12
@nglee
Copy link
Copy Markdown
Contributor Author

nglee commented Aug 27, 2020

@rgov It is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants