Using Optical Flow to warp an image

8 vues (au cours des 30 derniers jours)
QEWE
QEWE le 12 Déc 2011
Hi guys. I have computed the optical flow between images A and B. I wish to use this to warp image C to D. The problem is: the flow is a velocity vector with decimal values. Images are in the form of matrices for which rows and columns are integer values. Hence, C(i,j)+ optical flow(i,j) won't give me D(i,j) Please tell me how I can convert a matrix to a graph or how I can handle the decimal values. Thanks !!!
  2 commentaires
David Young
David Young le 12 Déc 2011
Do you have a single optic flow vector for the whole image, or a sparse set of optic flow vectors for some features in the image, or a dense set of optic flow vectors for each pixel in the image?
QEWE
QEWE le 14 Déc 2011
I've got a dense set of optic flow vectors for each pixel in the image.

Connectez-vous pour commenter.

Réponses (1)

David Young
David Young le 14 Déc 2011
Given a vector for every pixel, you can use interp2 to do the warping and to handle the non-integer lookup. Suppose that vx represents the x-component of the flow, such that the rightwards component of velocity at D(i,j) is x(i,j). Likewise vy is the y-component. Then you can do something similar to this:
C= imread('pout.tif'); % test image
[x, y] = meshgrid(1:size(C,2), 1:size(C,1));
% generate synthetic test data, for experimenting
vx = 0.1*y; % an arbitrary flow field, in this case
vy = 0.1*x; % representing shear
% compute the warped image - the subtractions are because we're specifying
% where in the original image each pixel in the new image comes from
D = interp2(double(C), x-vx, y-vy);
% display the result
imshow(D, []);
The bit that matters is the line in the middle with the call to interp2.
By the way, if you had a sparse set of flow vectors instead, you'd need to look at using imtransform with maketform.
  5 commentaires
QEWE
QEWE le 16 Déc 2011
Ok. I guess there was a problem with my optical flow code and the datatypes of matrices used. It works now. Thanks a lot for your solution !!! :)
Natesh Srinivasan
Natesh Srinivasan le 17 Mar 2013
@David
I think this is incorrect for non uniform flow fields. For Example, consider the following code, where A is the input image and B is the 'warped' image
function testinterpolation()
A = rand(5,5)
[X, Y] = meshgrid([1:5],[1:5]);
Mx = X/10;
My = Y/10;
xplusMx = X - Mx;
yplusMy = Y - My;
B = interp2 (A,xplusMx,yplusMy,'linear',0)
end
we cannot predict where a particular pixel has come from if by simply taking a minus sign because this could have been from a completely different pixel.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by