9

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 image blended 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
Honeybear
  • 2,928
  • 2
  • 28
  • 47
user3082220
  • 169
  • 1
  • 2
  • 6
  • 2
    The artifacts in the image are due to your panorama being slightly misaligned. They are not due to your blending code. which is creating a linear weighted blend between the overlapping images. You can see this misalignment even in your top image without the blending, on the misaligned top of the black building and the slightly misaligned crosses on the other large building. Maybe you need to do some bundle adjustment on your images to refine these small errors globally. – jcollomosse May 13 '14 at 19:58
  • I think I just want blend region to be about 10px from line, maybe it would help me. Now it's blending all overlap region – user3082220 May 14 '14 at 05:49
  • 3
    That would reduce the blurring except at the boundaries and you'll still see the artifacts due to bad alignment. Better would be to improve the alignment. – NoDataDumpNoContribution May 26 '14 at 11:21

2 Answers2

1

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.

mike
  • 791
  • 11
  • 26
1

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.

mxy
  • 331
  • 2
  • 9