Skip to content

docs: correct normalize factor in gaussian pyramid tutorial #21256

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
Dec 14, 2021

Conversation

zchrissirhcz
Copy link
Contributor

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

PR Notes

This PR change 16 to 256 for the gaussian pyramid tutorial. The tutorial use a 5x5 filter with elements sum up to 256, thus to normalize, the factor to be divided should be 256 instead of 16.

To verify if 256 is correct and 16 is not, I come up with the following test code locally, re-implement the pyramid down, and 256 is verified to be correct, 16 not correct.

void pyramidDown(const Mat& src, Mat& dst, const Size& _dsz = Size(),
        int  borderType = BORDER_DEFAULT
    )
{
    CV_Assert(borderType != BORDER_CONSTANT);
    Size dsz;
    if (_dsz.empty()) {
        fprintf(stderr, "!! dsz empty()\n");
        int src_width = src.size().width;
        int src_height = src.size().height;
        dsz.width = ( src_width + 1 ) / 2;
        dsz.height = ( src_height + 1 ) / 2;
    } else {
        fprintf(stderr, "!! dsz not empty()\n");
        dsz = _dsz;
    }

    float kernel_data[] = {
        1,  4,  6,  4,  1,
        4, 16, 24, 16,  4,
        6, 24, 36, 24,  6,
        4, 16, 24, 16,  4,
        1,  4,  6,  4,  1
    };
    Mat kernel(5, 5, CV_32FC1, kernel_data);
    kernel = kernel / 256;
    int ddepth = -1;
    Mat temp;
    filter2D(src, temp, ddepth, kernel);
    resize(temp, dst, Size(), 0.5, 0.5, INTER_NEAREST);
}

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.

Nice catch! Thank you 👍

@opencv-pushbot opencv-pushbot merged commit 330a118 into opencv:3.4 Dec 14, 2021
@zchrissirhcz zchrissirhcz deleted the fix-3.4-pyramid-tutorial branch December 15, 2021 00:21
@alalek alalek mentioned this pull request Dec 15, 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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants