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 argument interp selects the used interpolation method, and most be one of the following strings
"nearest"
- Nearest neighbor interpolation.
"linear"
"bilinear"
- Bilinear interpolation. This is the default behavior.
"cubic"
"bicubic"
- Bicubic interpolation.
All values of the result that fall outside the original image will be set to extrapval. For images of class
double
extrapval defaults toNA
and for other classes it defaults to 0.The optional output valid is a matrix of the same size as warped that contains the value 1 in pixels where warped contains an interpolated value, and 0 in pixels where warped contains an extrapolated value.
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); imshow(I); ## Resize the image to the double size and show it [XI, YI] = meshgrid(linspace(1, 100, 200)); warped = imremap(I, XI, YI); imshow(warped);
Produces the following figure
Figure 1 |
---|
![]() |
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); 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); imshow(warped);
Produces the following output
warning: imshow: pixels with NaN or NA values are set to minimum pixel value
and the following figure
Figure 1 |
---|
![]() |