Applies any geometric transformation to the image im.
The arguments XI and YI are lookup tables that define the resulting image
warped(y,x) = im(YI(y,x), XI(y,x))
where im is assumed to be a continuous function, which is achieved by interpolation. Note that the image im is expressed in a (X, Y)-coordinate system and not a (row, column) system.
The optional argument method defines the interpolation method to be
used. All methods supported by interp2
can be used. By default, the
linear
method is used.
For MATLAB compatibility, the methods bicubic
(same as
cubic
), bilinear
and triangle
(both the same as
linear
) are also supported.
All values of the result that fall outside the original image will be set to extrapval. The default value of extrapval is 0. For bicubic interpolation it is possible to apply padding instead. Valid padding methods are: "replicate", "symmetric", "reflect", "circular".
See also: imperspectivewarp, imrotate, imresize, imshear, interp2.
The following code
## Generate a synthetic image and show it I = tril(ones(100)) + abs(rand(100)); I(I>1) = 1; I(20:30, 20:30) = !I(20:30, 20:30); I(70:80, 70:80) = !I(70:80, 70:80); figure, imshow(I); ## Resize the image to the double size and show it [XI, YI] = meshgrid(linspace(1, 100, 200)); warped = imremap(I, XI, YI); figure, imshow(warped);
Produces the following figures
Figure 1 | Figure 2 |
---|---|
The following code
## Generate a synthetic image and show it I = tril(ones(100)) + abs(rand(100)); I(I>1) = 1; I(20:30, 20:30) = !I(20:30, 20:30); I(70:80, 70:80) = !I(70:80, 70:80); figure, imshow(I); ## Rotate the image around (0, 0) by -0.4 radians and show it [XI, YI] = meshgrid(1:100); R = [cos(-0.4) sin(-0.4); -sin(-0.4) cos(-0.4)]; RXY = [XI(:), YI(:)] * R; XI = reshape(RXY(:,1), [100, 100]); YI = reshape(RXY(:,2), [100, 100]); warped = imremap(I, XI, YI); figure, imshow(warped);
Produces the following figures
Figure 1 | Figure 2 |
---|---|
Package: image