How do I use interp2 with mesh grid to backwards warp one image onto another to create a mosaic?

31 Ansichten (letzte 30 Tage)
I'm trying to figure out how I can create a mosaic using interp2 and meshgrid. I've already used harris corners, normalized cross correlation, RANSAC and created a homography matrix. I'm fairly certain my homography matrix is correct, but it's not putting the warped image further to the right where I'd expect it to go. I think I'm finding the bounds of the new mosaic correctly.
I'm not sure where to go from here. How do you make sure that the warped image gets placed correctly in the mosaic and how do you blend the pixels where the images overlap?
Included all the files and points you'd need to run this. Picture of the correspondences and their locations at the bottom.
Thanks for your help.
% load files
load correspondences.mat % 1:2 are from the right image 3:4 are from the left
office = imageDatastore(fullfile(pwd));
image_r = double(mat2gray(rgb2gray(readimage(office,1))));
image_l = double(mat2gray(rgb2gray(readimage(office,2))));
% get the homography matrix
H = get_homography(correspondences);
% find the bounds of the mosaic
bounds = [floor(hom2cart((H * [1;512;1])')) floor(hom2cart((H * [1;340;1])'))];
mheight = bounds(4);
mwidth = bounds(2);
% backwards warp image1
h = inv(H); %backwards warping
[xi, yi] = meshgrid(1:mwidth,1:mheight);
xx = (h(1,1)*xi+h(1,2)*yi+h(1,3))./(h(3,1)*xi+h(3,2)*yi+h(3,3));
yy = (h(2,1)*xi+h(2,2)*yi+h(2,3))./(h(3,1)*xi+h(3,2)*yi+h(3,3));
warped_image = interp2(double(image_r), xx, yy);
% copy unwarp image and warped image to mosaic iamge
mosaic = zeros(mheight, mwidth);
mosaic(1:340, 1:512) = image_l;
% find overlapping regions - create masks?
% blend using averaging
% new_pixel = (pixel1 + pixel2) / 2
% mosaic() = new_pixel
figure(4);
imshow(warped_image)
axis on
figure(5);
imshow(mosaic);

Antworten (1)

Matt J
Matt J am 16 Mär. 2023
If you use imwarp instead of interp2, the OutputView setting can be used to specify where in the world coordinate system the transformed image should go.
  4 Kommentare
Jonathan Sullivan
Jonathan Sullivan am 16 Mär. 2023
Im not. That was the first part of my question. Thats the part im confused about.
Matt J
Matt J am 16 Mär. 2023
In your OP, you wrote " it's not putting the warped image further to the right where I'd expect it to go". Where do you expect it to go and why? What determines where it should go?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by