Is it similar to the cv::remap reprojection mapping function in opencv in matlab?

조회 수: 21(최근 30일)
As far as I know, I know interp2,interp,griddata,scatteredInterpolant and other functions can achieve my non-aligned regular grid data for mapping, but the efficiency is very low, on the contrary, the remap function in opencv is very fast and only does mapping projection. For example, I have the following non-gridded data points, known v = F(x,y), where x,y are non-regular data, I try to use scatteredInterpolant function for interpolation, but the computation time is up to several seconds.
My (x,y) coordinates data is in the following form:
load data.mat
validPtsX = double(validPtsX);
validPtsY = double(validPtsY);
[qX,qY] = meshgrid(1:W,1:H);
F = scatteredInterpolant(validPtsX(:),validPtsY(:),oriImg(:));
tic
undistortImg1 = F(qX,qY); % took too long !
toc
undistortImg2 = interp2(validPtsX,validPtsY,oriImg,qX,qY,"linear",0);% error: Grid arrays must have NDGRID structure.
However, I can quickly get my interpolated mapped image in OpenCV by using the following statement:
cv::Mat undistortImg;
cv::remap(oriImg, undistortImg, mapX, mapY, cv::INTER_LINEAR); // Supports both grid and non-grid data mapping
update:
It is verified that the interp2 function has equivalent mapping power and execution speed to the cv::remap function when the mapping matrix mapX,mapY (or called queryX,queryY) is computed in advance!
undistortImg = interp2(img,mapX,mapY,"linear",0);% 等价OpenCV的cv::remap函数,速度在各自环境下等价一致!

채택된 답변

cui
cui 2022년 6월 25일
편집: cui 2022년 6월 25일
use "interp2" function!
The similarities and differences between "cv::remap" in opencv and "interp2" in matlab:
Main common point: both can interpolate (retrieval location does not belong to the source index) and map (retrieval location belongs to the source index) the image array, indexed with the same grid belonging to the image array.
The main difference: cv::remap is designed only for image arrays, that is, the known source index x,y must be non-negative positive integers incrementing from 0 (corresponding to matlab 1); while matlab's interp2 is designed for general array matrices, that is, both for image arrays and for other arbitrary arrays, the known source index does not have to start from 1 (corresponding to opencv for 0), if you do not specify the first two input parameters x,y, then by default and cv::remap function function function the same.
In summary, opencv "cv::remap" is only a small part of matlab's interp2 function, they can both interpolate and remap, but interp2 can complete all cv::remap all function, and vice versa.
opencv中"cv::remap"和matlab的"interp2"函数异同:
主要共同点:都可以对图像数组进行插值(检索位置不属于源索引)和映射(检索位置属于源索引),索引同属于图像数组的grid网格。
主要不同点:cv::remap只针对图像数组进行设计,即已知的源索引x,y必须是从0(对应matlab为1)开始递增的非负正整数;而matlab的interp2是针对通用的数组矩阵进行设计,即既可以对图像数组进行也可以对其他任意数组进行操作,已知的源索引不必从1(对应opencv为0)开始,如果不指定第一,二个输入参数x,y,则默认和cv::remap函数功能一样。
综上所述,opencv中“cv::remap”实现的只是matlab的interp2函数的一小部分功能,它们既可以插值也可以重映射,但interp2可以完成所有cv::remap所有功能,反之不行。

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by