定义
仿射变换是从二维坐标到二维坐标的线性变换,且保持二维图像的平直性和平行性。仿射变换也可通过一系列的原子变换的复合来实现,包括平移,缩放,翻转,旋转和剪切。针对平面上的物体位姿变化。可通过矩阵描述,将输入图像与变换矩阵进行矩阵乘法得到变换后的图像坐标。
相应函数
void warpAffine(comst oclMat &src,oclMat &dst,const Mat &M,Size dsize,int flags = INTER_LINEAR)
Parameters: src- Source image 输入图像
dst- Destination matrix 变化后图像
M- 2times 3 transformation matrix 2*3的变换矩阵
dsize- Size of the destination image 输出图像大小
flags- Acombination of interpoloation methods 差值算法
enum InterpolationFlags{
/** nearest neighbor interpolation */
INTER_NEAREST = 0, //最近邻插值
/** bilinear interpolation */
INTER_LINEAR = 1, //双线性插值
/** bicubic interpolation */
INTER_CUBIC = 2, //双三次插值
/** resampling using pixel area relation. It may be a preferred method for image decimation, as
it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
method. */
INTER_AREA = 3, //区域插值,使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现。当图像放大时,类似于 <span style="font-family: Arial, Helvetica, sans-serif;">INTER_NEAREST</span>方法
/** Lanczos interpolation over 8x8 neighborhood */
INTER_LANCZOS4 = 4, //Lanczos插值(超过8×8像素邻域的Lanczos插值)
/** mask for interpolation codes */
INTER_MAX = 7,
/** flag, fills all of the destination image pixels. If some of them correspond to outliers in the
source image, they are set to zero */
WARP_FILL_OUTLIERS = 8, //填充所有输出图像的象素
/** flag, inverse transformation
For example, polar transforms:
- flag is __not__ set: \f$dst( \phi , \rho ) = src(x,y)\f$
- flag is set: \f$dst(x,y) = src( \phi , \rho )\f$
*/
WARP_INVERSE_MAP = 16 //逆变换
};
功能:根据getAffineTransform或getRotationMatrix2D得到的变换矩阵,计算变换后的图像。
getAffineTransform(InoutArray src,InputArray dst)
Parameters: src- 原图像
dst- 转换后的图像
功能:已知图像变换前后的坐标,返回相应的变换矩阵。适用于目标检测场合,通过检测得到的特征点进行图像匹配。Mat getRotationMatrix2D
(Point2f center,double angle,double scale)
功能:已知旋转中心坐标(坐标原点为图像左上端点) 、旋转角度(单位为度°,顺时针为负,逆时针为正)、缩放比例、返回旋转/缩放矩阵。
详解
任意一个仿射变换都可表示为乘以一个矩阵(线性变换)再加上一个向量(平移)。仿射变换为2*3的矩阵
矩阵A,B对二维向量X = 做变换
因为仿射变换实际上是通过矩阵描述了两张图片之间的关联,所以存在以下两种情况:
已知原图片中三个点和变化后的图片与之相对应的三个点,求对应的矩阵。
已知对应的矩阵和原图片,求变化后的图片。
其中,M为矩阵,X为原图像信息,T为变换后的图像信息。T=X*M。