source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/3dRecon/utils/homogWarp.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.5 KB
Line 
1function result = homogWarp(im, H, szIm, grayDefault)
2 %% result = homogWarp(im, H, szIm, grayDefault) 
3 %% Warp the input image by the 2D homography H.  The output
4 %% image, result, is to be of size szIm, with x going from 0 to szIm(2)
5 %% and y going from 0 to szIm(1).  By default, szIm = size(im).
6 %% grayDefault is the gray level to use for points in the new image
7 %% that cannot be mapped from the original image im.
8 %% Note, the warp H is arranged such that a pixel (x,y) in
9 %% the result image comes from pixel (p1/p3, p2/p3) in the original
10 %% image im, where (p1 p2 p3)^T = H * (x,y,1)^T.  (If you don't get
11 %% the desired result, try using the inverse of H.)
12   
13 if nargin < 3
14   % size of the image
15   szIm = size(im);
16 end
17 if nargin < 4
18   % default gray value
19   grayDefault = 127;
20 end
21 
22 % pixel coordinates in original image
23 [x,y] = meshgrid(1:size(im,2),1:size(im,1));
24
25 % pixel coordinates in result image
26 if any(szIm ~= size(im))
27   [xp,yp] = meshgrid(1:szIm(2),1:szIm(1));
28   pix   = [xp(:)'; yp(:)'];
29 else
30   pix   = [x(:)'; y(:)'];
31 end
32 
33% homogeneous pixels in result frame.
34hPixels = [ pix; ones(1,prod(szIm))];
35
36% corresponding warped points in original frame
37hScene  = H*hPixels;
38
39% pixel coords in original frame.
40xprime=(hScene(1,:)./(hScene(3,:)))';
41yprime=(hScene(2,:)./(hScene(3,:)))';
42xprime = reshape(xprime, szIm);
43yprime = reshape(yprime, szIm);
44
45% Warping an image according to the homography
46result = interp2(x,y,im,xprime,yprime, '*linear');
47result(isnan(result)) = grayDefault;
48result = reshape(result,szIm);
49
Note: See TracBrowser for help on using the repository browser.