Skip to content

Added flag to GaussianBlur for faster but not bit-exact implementation#25792

Merged
asmorkalov merged 8 commits intoopencv:4.xfrom
asmorkalov:as/HAL_fast_GaussianBlur
Jul 12, 2024
Merged

Added flag to GaussianBlur for faster but not bit-exact implementation#25792
asmorkalov merged 8 commits intoopencv:4.xfrom
asmorkalov:as/HAL_fast_GaussianBlur

Conversation

@asmorkalov
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov commented Jun 20, 2024

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts borderType parameter to more generic flags and introduces GAUSS_ALLOW_APPROXIMATIONS flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces #22073
Possibly related issue: #24135

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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

@asmorkalov asmorkalov added this to the 4.11.0 milestone Jun 20, 2024
@asmorkalov asmorkalov force-pushed the as/HAL_fast_GaussianBlur branch 2 times, most recently from 1c62df7 to b5df286 Compare June 20, 2024 10:16
@asmorkalov asmorkalov changed the title Added flag to GaussianBlur for faster but not bit-exact implementation. Added flag to GaussianBlur for faster but not bit-exact implementation Jun 20, 2024
@asmorkalov asmorkalov force-pushed the as/HAL_fast_GaussianBlur branch 2 times, most recently from 671ce14 to ea56bd9 Compare June 20, 2024 12:37
@asmorkalov asmorkalov added the pr: needs test New functionality requires minimal tests set label Jun 20, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor Author

Discussion result:

  • move enum to core
  • dedicated parameter for perf hint, do not mix with border type.
  • check python and java bindings

@asmorkalov asmorkalov added category: core test and removed pr: Discussion Required pr: needs test New functionality requires minimal tests set labels Jun 25, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor Author

@mshabunin @opencv-alalek @vpisarev I reworked interface as discussed offline and added accuracy tests for IPP branch. Could you take a look?

@asmorkalov asmorkalov force-pushed the as/HAL_fast_GaussianBlur branch from a753443 to 8fa2e47 Compare July 10, 2024 11:49
@vpisarev vpisarev self-requested a review July 10, 2024 19:22
cv::absdiff(dst, gt, diff);
cv::Mat flatten_diff = diff.reshape(1, diff.rows);

int nz = countNonZero(flatten_diff);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

norm is faster than countNonZero approach.

Use relative NORM_L1/L2 and NORM_INF instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I intentionally split the check on min-max deviation and amount of different pixels.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EXPECT_LE(max_val, 2); // expectes results floating +-1

comment doesn't follow to the check anyway.

NORM_INF <=1 works perfect.

With 1-limited NORM_INF, we could use NORM_L1 + RELATIVE to define the part of pixels of different values.

@asmorkalov asmorkalov added feature and removed RFC labels Jul 11, 2024
@asmorkalov
Copy link
Copy Markdown
Contributor Author

@opencv-alalek I fixed your review notes. Please take a look again.

@asmorkalov asmorkalov force-pushed the as/HAL_fast_GaussianBlur branch from a47f442 to ee840b5 Compare July 11, 2024 09:48
@asmorkalov asmorkalov force-pushed the as/HAL_fast_GaussianBlur branch from ee840b5 to 13b6caa Compare July 11, 2024 11:04
@asmorkalov asmorkalov merged commit 15783d6 into opencv:4.x Jul 12, 2024
ALGO_APPROX = 2, //!< Allow alternative approximations to get faster implementation. Behaviour and result depends on a platform
};

/*! @brief Returns ImplementationHint selected by default, a.k.a. `IMPL_DEFAULT` defined during OpenCV compilation.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ImplementationHint

not renamed


IMPL_DEFAULT

What is that?

*/
enum AlgorithmHint {
ALGO_DEFAULT = 0, //!< Default algorithm behaviour defined during OpenCV build
ALGO_ACCURATE = 1, //!< Use generic portable implementation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ALGO_HINT_ then.

#include <iostream>
#include <ostream>

#include <opencv2/core.hpp>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be removed.


/*! @brief Returns ImplementationHint selected by default, a.k.a. `IMPL_DEFAULT` defined during OpenCV compilation.
*/
CV_EXPORTS_W AlgorithmHint getDefaultAlgorithmHint();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should go to utility.hpp somewhere near setUseOptimized()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

setUseOptimized() should also control behavior of that:

  • setUseOptimized(false) disables these hints and use accurate versions.

cv::absdiff(dst, gt, diff);
cv::Mat flatten_diff = diff.reshape(1, diff.rows);

int nz = countNonZero(flatten_diff);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

EXPECT_LE(max_val, 2); // expectes results floating +-1

comment doesn't follow to the check anyway.

NORM_INF <=1 works perfect.

With 1-limited NORM_INF, we could use NORM_L1 + RELATIVE to define the part of pixels of different values.

asmorkalov added a commit that referenced this pull request Aug 6, 2024
Added xxxApprox overloads for YUV color conversions in HAL and AlgorithmHint to cvtColor #25932

The xxxApprox to implement HAL functions with less bits for arithmetic of FP.

The hint was introduced in #25792 and #25911

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
fengyuentau pushed a commit to fengyuentau/opencv that referenced this pull request Aug 15, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
fengyuentau pushed a commit to fengyuentau/opencv that referenced this pull request Aug 15, 2024
Added xxxApprox overloads for YUV color conversions in HAL and AlgorithmHint to cvtColor opencv#25932

The xxxApprox to implement HAL functions with less bits for arithmetic of FP.

The hint was introduced in opencv#25792 and opencv#25911

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 1, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
@savuor savuor mentioned this pull request Nov 1, 2024
6 tasks
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 5, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 8, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
savuor pushed a commit to savuor/opencv that referenced this pull request Nov 21, 2024
Added flag to GaussianBlur for faster but not bit-exact implementation opencv#25792

Rationale:
Current implementation of GaussianBlur is almost always bit-exact. It helps to get predictable results according platforms, but prohibits most of approximations and optimization tricks.

The patch converts `borderType` parameter to more generic `flags` and introduces `GAUSS_ALLOW_APPROXIMATIONS` flag to allow not bit-exact implementation. With the flag IPP and generic HAL implementation are called first. The flag naming and location is a subject for discussion.

Replaces opencv#22073
Possibly related issue: opencv#24135

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] 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
thewoz pushed a commit to CobbsLab/OPENCV that referenced this pull request Feb 13, 2025
Added xxxApprox overloads for YUV color conversions in HAL and AlgorithmHint to cvtColor opencv#25932

The xxxApprox to implement HAL functions with less bits for arithmetic of FP.

The hint was introduced in opencv#25792 and opencv#25911

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants