Biomedical Engineering Reference
In-Depth Information
In homogeneous coordinate systems, an isotropic scaling transformation
matrix is
⎡
⎤
s
00
0
s
0
001
⎣
⎦
,
S
=
where
s
is the scaling factor. The rotation matrix is
⎡
⎤
cos
θ
sin
θ
0
⎣
⎦
,
R
=
−
sin
θ
cos
θ
0
0
0
1
where
θ
is the rotation angle. The transformation matrix corresponding to the
translation is
⎡
⎣
⎤
⎦
,
10
t
x
01
t
y
00 1
T
=
where
t
x
and
t
y
are translation offsets.
A successive transformation amounts to multiplication of corresponding
matrices. We enforce the order of operations as scaling, rotation, and then
translation, in matrix form,
T
·
R
·
S
. We seek (
s
,θ,
t
x
,
t
y
) parameters and these
parameters are applied to the floating image in the order discussed above.
An affine transform can be easily composed in Java:
AffineTransform at = new AffineTransform ();
at.translate(tx, ty);
at.scale(scale, scale);
at.rotate(Math.PI/180.0*angle);
To create a transformed image, one can invoke the
filter
method of the
AffineTransformOp, which can be constructed from the rendering hints and
affine transform. The Java code is similar to
RenderingHints rh = new RenderingHints(/* specify here */);
AffineTransform at = new AffineTransform();
// define transform here
AffineTransformOp atop = new AffineTransformOp(at, rh);
BufferedImageOp biop = (BufferedImageOp) atop;
BufferedImage bi = biop.filter(bi, null);