仿射变换的学习
本次实验做一个放射扭曲的一个简单例子,将图像放到另一张图片中,使其能够和指定区域对齐。
实验步骤如下:
1.得到im1图与im2图的图像数组
2.将tp赋值为im1图中映射到im2图的位置(上下左右四个点)数组,fp赋值为关于B图四个顶点的数组
3.使得tp是fp经过仿射变换H矩阵得到的。
4.利用得到的H矩阵对A图进行扭曲处理得到im1_t。
5.创建alpha图像
3.根据alpha图像的权值得到图像im3,即最后的结果
以下将根据上面的步骤代入代码,分析原理。
# -*- coding: utf-8 -*-
from PCV.geometry import warp, homography
from PIL import Image
from pylab import *
from scipy import ndimage
# example of affine warp of im1 onto im2
im1 = array(Image.open('C:/Users/LENOVO/Desktop/计算机视觉/ch2/images/131.jpg').convert('L'))
im2 = array(Image.open('C:/Users/LENOVO/Desktop/计算机视觉/ch2/images/130.jpg').convert('L'))
# set to points
tp = array([[240,340,340,240],[200,200,300,300],[1,1,1,1]])#四个点
#tp = array([[675,826,826,677],[55,52,281,277],[1,1,1,1]])
im3 = warp.image_in_image(im1,im2,tp)
figure