经过图割过后,图像的每一块分布在了不同的图像,直接拼接在一起会有明显的接缝,为了解决这个问题需要用到泊松融合。
这里与poisson image edit不同的是这里不是一块一块两两融合到一起的,而是一次性全图融合到一块。
其重要思路是:
1.每一个块在自己的原图像中计算梯度
2.将梯度根据块拼接在一起,形成合成的梯度图
3.用这个梯度图计算散度
4.泊松等式求解Ax=b
需要注意的是这里用到的是第二类边界,而不是第一类边界。
下面是计算b的代码 b是一个列向量
templt = [0 0 0; 0 -1 1; 0 0 0];
GR1 = imfilter(double(TargetImgR), templt, 'replicate');%Rx梯度
GG1 = imfilter(double(TargetImgG), templt, 'replicate');%Gx梯度
GB1 = imfilter(double(TargetImgB), templt, 'replicate');%Bx梯度
templt = [0 0 0; 0 -1 0; 0 1 0];
GR2 = imfilter(double(TargetImgR), templt, 'replicate');%Ry梯度
GG2 = imfilter(double(TargetImgG), templt, 'replicate');%Gy梯度
GB2 = imfilter(double(TargetImgB), templt, 'replicate');%By梯度
templt = [0 0 0; -1 1 0; 0 0 0];
VR1 = imfilter(double(GR1), templt, 0);%Rx散度
VG1 = imfilter(double(GG1), templt, 0);%Gx散度
VB1 = imfilter(double(GB1), templt, 0);%Bx散度
templt = [0 -1 0; 0 1