-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
phaseCorrelate fails with larger 16bit images #25737
Copy link
Copy link
Closed
Labels
Milestone
Description
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)
Reactions are currently unavailable