Using Optical Flow to warp an image
이전 댓글 표시
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
David Young
2011년 12월 12일
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
2011년 12월 14일
답변 (1개)
David Young
2011년 12월 14일
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
QEWE
2011년 12월 15일
QEWE
2011년 12월 15일
David Young
2011년 12월 15일
The example I gave works, so I'm not sure why you are not getting the results you expect with your data. interp2 does indeed ensure that every pixel moves as specified by vx and vy for that pixel. Are you sure that your vx and vy arrays are correct?
QEWE
2011년 12월 16일
Natesh Srinivasan
2013년 3월 17일
@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.
카테고리
도움말 센터 및 File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!