Skip to content

Allow using more types with LUT, findNonZero, and PSNR. - #11364

Closed
Tetragramm wants to merge 31 commits into
opencv:masterfrom
Tetragramm:Type_Fixes_core
Closed

Tetragramm wants to merge 31 commits into
opencv:masterfrom
Tetragramm:Type_Fixes_core

Conversation

@Tetragramm

@Tetragramm Tetragramm commented Apr 21, 2018 •

Copy link
Copy Markdown
Contributor

Allow using more types with LUT, findNonZero, and PSNR.
Fix comment error in Rotate.

This is the first step in making sure all (or as many as I can get done) functions work with all the datatypes the can possibly accept. This takes the functions in core/operations on arrays and updates them. I believe that this is everything in core that needs to be updated, though if someone finds something else, just let me know.

buildworker:Linux x64=linux-1
buildworker:Win64 OpenCL=windows-2

Tetragramm and others added 27 commits September 28, 2015 19:00
… the SSE2 code from cmp_16u to cmp_smid<ushort>
# Conflicts:
#	modules/core/src/arithm.cpp
#	modules/hal/src/stat.cpp
# Conflicts:
#	modules/core/src/mathfuncs_core.cpp
# Conflicts:
#	modules/core/include/opencv2/core.hpp
#	modules/core/src/copy.cpp
#	modules/imgproc/src/clahe.cpp
# Conflicts:
#	modules/flann/include/opencv2/flann/logger.h
@vpisarev vpisarev self-assigned this Apr 21, 2018

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Missing tests.

  2. LUT32s_32s requires 16Gb for LUT table.

  3. Compare impact on size of OpenCV binaries.

  4. Check performance, including changes in OpenCL code for LUT code.

Fixed the precommit hook, so the whitespace error should go away too.
@Tetragramm

Tetragramm commented Apr 21, 2018 •

Copy link
Copy Markdown
Contributor Author

Added tests.
New LUT does not support 32S for precisely that reason.
As for binary size, is there a way to get that out of the build bot? I can always do the comparison on my builds, but the compiler flags may be different than the published version.
On my local builds, it's 10 KB more for this entire PR.

Performance tests coming.

Hmm, the pre-commit hook didn't catch the error, although it did catch some others. Am I using it wrong, or is that just outside it's patterns?

Fix whitespace error in lut.cpp, I think.
@Tetragramm

Copy link
Copy Markdown
Contributor Author

Performance Tests. Only OCL changed, so only those are shown.
I think I can get this back to close to the original, if we want to. Small images see a pretty nice performance boost. Have to do some fiddling to restore local memory if the input type is 8U or 8S.

Test Old New
OCL_LUT/0 (17 ms) (2 ms)
OCL_LUT/1 (12 ms) (3 ms)
OCL_LUT/2 (14 ms) (9 ms)
OCL_LUT/3 (13 ms) (8 ms)
OCL_LUT/4 (4 ms) (6 ms)
OCL_LUT/5 (5 ms) (7 ms)
OCL_LUT/6 (12 ms) (19 ms)
OCL_LUT/7 (18 ms) (29 ms)
OCL_LUT/8 (8 ms) (15 ms)
OCL_LUT/9 (13 ms) (18 ms)
OCL_LUT/10 (20 ms) (40 ms)
OCL_LUT/11 (40 ms) (44 ms)
OCL_LUT/12 (23 ms) (40 ms)
OCL_LUT/13 (46 ms) (55 ms)
OCL_LUT/14 (79 ms) (156 ms)
OCL_LUT/15 (146 ms) (177 ms)
OCL_LUT/total (470 ms total) (629 ms total)

@vpisarev

vpisarev commented Jun 4, 2018 •

Copy link
Copy Markdown
Contributor

that's a serious code expansion. Do we really need all this functionality? Can we make it more compact by taking into account the fact that for some of the types the code will actually be the same (e.g. findNonZero for 8u and 8s). Then, speaking of findNonZero, why not just use

findNonZero(myarray != 0., nz_locs_array)

where myarray is single-channel array of an arbitrary depth?

@Tetragramm

Copy link
Copy Markdown
Contributor Author

It depends on whether you are worried about binary size or lines of code. It would prevent the creation of two template specializations, but only 4 lines of code. Even then, the template function isn't very large.

As to using != 0, that allocates and deallocates a Mat, and all the extra comparisons, reads, and writes.

I intend on continuing the expansion of data type support (particularly CV_16U) in other modules, and for that, having all the basic functions (LUT specifically) compatible is important.

@vpisarev

vpisarev commented Jun 6, 2018

Copy link
Copy Markdown
Contributor

@Tetragramm, we are now working on integrating some "mini" version of Halide into OpenCV, with intention to 1) reduce the OpenCV binary size by factor of 2 or so and 2) give user ability to build relatively simple custom pipelines that will run very efficiently w/o introducing many manually written functions or function flavors. I think, it would be much better way of solving the problem of missing datatype support in certain functions

@Tetragramm

Tetragramm commented Jun 6, 2018 via email

Copy link
Copy Markdown
Contributor Author

vpisarev added a commit to vpisarev/opencv that referenced this pull request Jun 26, 2018
…ero & PSNR to support more types, not just 8u.
@vpisarev

Copy link
Copy Markdown
Contributor

superseded by #11837; for LUTs, I think, we need some better solutions, like LUT with interpolation (e.g. pass the grid and the value range (e.g. 0 to 65535 range and 16x16x16 grid for 16-bit RGB to 16-bit RGB 3D transformation)). In fact, we already have something like that internally for some of our color conversion functions

@vpisarev vpisarev closed this Jun 26, 2018
vpisarev added a commit that referenced this pull request Jun 26, 2018
* a part of #11364 by Tetragramm. Rewritten and extended findNonZero & PSNR to support more types, not just 8u.

* fixed compile & doxygen warnings

* fixed small bug in findNonZero test
luzpaz pushed a commit to luzpaz/opencv that referenced this pull request Jul 31, 2018
* a part of opencv#11364 by Tetragramm. Rewritten and extended findNonZero & PSNR to support more types, not just 8u.

* fixed compile & doxygen warnings

* fixed small bug in findNonZero test
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* a part of opencv#11364 by Tetragramm. Rewritten and extended findNonZero & PSNR to support more types, not just 8u.

* fixed compile & doxygen warnings

* fixed small bug in findNonZero test
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
* a part of opencv#11364 by Tetragramm. Rewritten and extended findNonZero & PSNR to support more types, not just 8u.

* fixed compile & doxygen warnings

* fixed small bug in findNonZero test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants