1 | initial version |
If you have the formula and the parameters, you can use it directly on the image.
for(int y=0;y<src.rows;y++)
for(int x=0;x<src.cols;x++) {
xp=A+B*x+C*y+D*x*x+E*x*y+F*y*y;
yp=G+H*x+I*y+J*x*x+K*x*y+L*y*y;
dst.at<uchar>(xp,yp)=src+at(x,y);
}
or, even better, compute the inverse function: x=M+Nx'+Oy'+Px'x'+Qx'y'+Ry'y'... and do the same by iterating xp and yp.
Note: check if xp and yp are in the image before setting them.
If it works well, you can to parallelize the outer loop using TBB to make it very fast.
Concerning the rotation and scale: they are still affine operations, so they affect the x and y terms. So you can get their values using the B and C parameters.
2 | No.2 Revision |
If you have the formula and the parameters, you can use it directly on the image.
for(int y=0;y<src.rows;y++)
for(int x=0;x<src.cols;x++) {
xp=A+B*x+C*y+D*x*x+E*x*y+F*y*y;
yp=G+H*x+I*y+J*x*x+K*x*y+L*y*y;
dst.at<uchar>(xp,yp)=src+at(x,y);
dst.at<uchar>(xp,yp)=src.at<uchar>at(x,y);
}
or, even better, compute the inverse function: x=M+Nx'+Oy'+Px'x'+Qx'y'+Ry'y'... and do the same by iterating xp and yp.
Note: check if xp and yp are in the image before setting them.
If it works well, you can to parallelize the outer loop using TBB to make it very fast.
Concerning the rotation and scale: they are still affine operations, so they affect the x and y terms. So you can get their values using the B and C parameters.