我在matlab中尝试缝合图像,但得到难看的重叠线条.如何正确混合图像?目前我正在使用下面的代码,但它混合得太多(特别是建筑物窗户与鬼魂文物混合,黑色建筑物也是如此).
%Tx - how much to move picture by x, Ty - by y (homography)
cropX = size(imcyl2, 2); %second image x size
xdimfirst = size(imcyl1, 2); %first image x size
ydimfirst = size(imcyl1, 1); %first image y size
xoverlap = xdimfirst - Tx;
newImg = imcyl1;
for y = 1:size(imcyl2, 1)
for x = 1:cropX
if ((Tx+x) > 0 && (Ty+y) >0)
% if we are in the overlap region, then we need to blend.
scale1 = (xoverlap - x) / xoverlap;
scale2 = x / xoverlap;
r = scale1 * imcyl1(Ty + y, Tx + x, 1) + scale2 * imcyl2(y, x, 1);
g = scale1 * imcyl1(Ty + y, Tx + x, 2) + scale2 * imcyl2(y, x, 2);
b = scale1 * imcyl1(Ty + y, Tx + x, 3) + scale2 * imcyl2(y, x, 3);
newImg(Ty + y, Tx + x, :) = [r g b];
end
end
end