imwarp() - Image Processing
B = imwarp(A,tform) transforms
the image A according to the geometric transformation
defined by tform, which is a geometric transformation
object. B is the transformed image.B = imwarp(A,D) transforms
the input image A according to the displacement
field defined by D. [B,RB] =
imwarp(A,RA,tform) transforms
the spatially referenced image, specified by the image data A and
the associated spatial referencing object RA.
The output is a spatially referenced image specified by the image
data B and the associated spatial referencing
object RB.B = imwarp(___,Interp) specifies
the form of interpolation to use[B,RB] =
imwarp(___,Name,Value) specifies
parameters that control various aspects of the geometric transformation.
Parameter names can be abbreviated, and case does not matter.Code Generation support:
Yes.MATLAB Function Block support:
Yes.
Syntax
B = imwarp(A,tform) exampleB = imwarp(A,D)[B,RB] =
imwarp(A,RA,tform)B = imwarp(___,Interp)[B,RB] =
imwarp(___,Name,Value)
Example
Apply Horizontal Shear to ImageOpen This Example
Read grayscale image into workspace and display it.I = imread('cameraman.tif');
imshow(I)
Create a 2-D geometric transformation object.tform = affine2d([1 0 0; .5 1 0; 0 0 1])
tform =
affine2d with properties:
T: [3x3 double]
Dimensionality: 2
Apply the transformation to the image.J = imwarp(I,tform);
figure
imshow(J)
Apply Rotation Transformation to 3-D MRI DatasetOpen This Example
Read MRI data into the workspace and visualize it.s = load('mri');
mriVolume = squeeze(s.D);
sizeIn = size(mriVolume);
hFigOriginal = figure;
hAxOriginal = axes;
slice(double(mriVolume),sizeIn(2)/2,sizeIn(1)/2,sizeIn(3)/2);
grid on, shading interp, colormap gray
Create a 3-D geometric transformation object. First create a transformation matrix that rotates the image around the Y axis. Then pass the matrix to the affine3d function. theta = pi/8;
t = [cos(theta) 0 -sin(theta) 0
0 1 0 0
sin(theta) 0 cos(theta) 0
0 0 0 1]
tform = affine3d(t)
t =
0.9239 0 -0.3827 0
0 1.0000 0 0
0.3827 0 0.9239 0
0 0 0 1.0000
tform =
affine3d with properties:
T: [4x4 double]
Dimensionality: 3
Apply the transformation to the image.mriVolumeRotated = imwarp(mriVolume,tform);
Visualize three slice planes through the center of the transformed volumes.sizeOut = size(mriVolumeRotated);
hFigRotated = figure;
hAxRotated = axes;
slice(double(mriVolumeRotated),sizeOut(2)/2,sizeOut(1)/2,sizeOut(3)/2);
grid on, shading interp, colormap gray
Link views of both axes together.linkprop([hAxOriginal,hAxRotated],'View');
Set view to see effect of rotation.set(hAxRotated,'View',[-3.5 20.0])
Output / Return Value
Limitations
Alternatives / See Also
Reference