Skip to content

phaseCorrelate fails with larger 16bit images #25737

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

Closed
4 tasks done
rlexmann opened this issue Jun 10, 2024 · 0 comments
Closed
4 tasks done

phaseCorrelate fails with larger 16bit images #25737

rlexmann opened this issue Jun 10, 2024 · 0 comments

Comments

@rlexmann
Copy link
Contributor

rlexmann commented Jun 10, 2024

System Information

OpenCV version: 4.10.0
Operating System / Platform: Windows 11 Pro
Compiler & compiler version: MSVC 19.29.30154

Detailed description

With larger (~4000x4000px) uint16 images converted to float32, phaseCorrelate sometimes fails because infs and NaNs appear in divSpectrums().

Steps to reproduce

#include <opencv2/imgproc.hpp>
int main(int argc, char ** argv) {
    using namespace cv;

    // load
    Mat im = imread("<path/to/opencv_extra>/testdata/shared/baboon.png", IMREAD_GRAYSCALE);
    assert(im.type() == CV_8UC1);

    // convert to 32F, scale values as if original image was 16U
    constexpr auto u8Max = std::numeric_limits<std::uint8_t>::max();
    constexpr auto u16Max = std::numeric_limits<std::uint16_t>::max();
    im.convertTo(im, CV_32FC1, double(u16Max) / double(u8Max));

    // enlarge and create ROIs
    const auto w = im.cols * 5;
    const auto h = im.rows * 5;
    const auto roiW = (w * 2) / 3; // 50% overlap
    Mat imLarge;
    resize(im, imLarge, { w, h });
    const auto roiLeft = imLarge(Rect(0, 0, roiW, h));
    const auto roiRight = imLarge(Rect(w - roiW, 0, roiW, h));

    // correlate
    double response = 0.0;
    Point2d phaseShift = phaseCorrelate(roiLeft, roiRight, cv::noArray(), &response);
    assert(std::isnormal(phaseShift.x) || 0.0 == phaseShift.x);
    assert(std::isnormal(phaseShift.y) || 0.0 == phaseShift.y);
    assert(std::isnormal(response) || 0.0 == response);

    return 0;
}

Test data: baboon.png

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants