I'm trying stitch images in matlab, but get ugly overlap lines. How can I blend images properly? Currently I'm using the code below, but it blends too much (especially building windows are blended with ghost artifacts, as is the black building).
%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
Try using the best camera technique at first (tripod and rotating head etc). Better data = better results.
My next best bet is a gradually reduced blending. Something like:
blendfactor = dist_to_border^2;
Or some exponential thing. If this is a one time thing, I'd go for a photography software like gimp. If it's gonna be serious, you can try to estimate the pixels position in the other frame by pattern search.
If you still working on the problem, I believe what you need to do is a color correction step between overlapping images. For example, The blue sky from the most left image and the second image from the left should have the same blue value. Clearly they don't due to the camera vignetting on the corners. By making sure both blue values fall in a close range from each other, you will have a better blending.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With