Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to blend properly when stitching images in matlab?

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).

unblended imageblended image

%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
like image 692
user3082220 Avatar asked May 13 '14 17:05

user3082220


2 Answers

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.

like image 110
mike Avatar answered Sep 28 '22 04:09

mike


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.

like image 42
mxy Avatar answered Sep 28 '22 06:09

mxy