📄 393-399.html
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Image Processing in Java</TITLE>
<!-- HEADER --><STYLE type="text/css"> <!-- A:hover { color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=9//-->
<!--PAGES=393-399//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="389-393.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="399-404.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading29"></A><FONT COLOR="#000077">Two-Dimensional Rotation</FONT></H4>
<P>An example of rotation about the center of an image is shown in Figure 9.16.
</P>
<P><A NAME="Fig16"></A><A HREF="javascript:displayWindow('images/09-16.jpg',128,128 )"><IMG SRC="images/09-16t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-16.jpg',128,128)"><FONT COLOR="#000077"><B>Figure 9.16</B></FONT></A> Lena rotated about the center of the frame.</P>
<P>To rotate about the center of an image, first translate the center to the origin, rotate, and then translate back.
</P>
<P>To rotate a point, <I>p</I>, whose coordinates are (<I>p</I>.<I>x</I>,<I>p</I>.<I>y</I>) plane by an amount, [theta], about the origin, use the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-39d.jpg"></P>
<P>(9.25)
</P>
<P>To rotate about a point, <I>t</I>, first translate to the origin, perform the rotation, and then translate back. This process can be represented by the following column vector:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-40d.jpg"></P>
<P>(9.26)
</P>
<P>Positive angles are measured counterclockwise. You should be able to reformulate the rotational transformations for negative angles. Use these identities:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-41d.jpg"></P>
<P>Now let’s look at proof of
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-42d.jpg"></P>
<P>Suppose that a complex number of magnitude <I>r</I> represents <I>p</I> so that <I>p</I> = <I>rei</I>[theta], Then rotation, with respect to the origin, by an amount of [theta], can be calculated by multiplication via another complex number, <I>p</I>[theta] = <I>e<SUP>i</SUP></I>[theta] so that</P>
<P ALIGN="CENTER"><IMG SRC="images/09-43d.jpg"></P>
<P>(9.27)
</P>
<P>By Euler's relation, <I>e<SUP>i</I>[theta]</SUP> = cos[theta] +<I>i</I>sin[theta], we obtain</P>
<P ALIGN="CENTER"><IMG SRC="images/09-44d.jpg"></P>
<P>(9.28)
</P>
<P>We then invoke the double angle formulas for sine and cosine to obtain the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-45d.jpg"></P>
<P>(9.29)
</P>
<P>Recall that <I>p = re<SUP>i</I>[phi]</SUP> is, by Euler’s relation, the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-46d.jpg"></P>
<P>(9.30)
</P>
<P>Substituting Equation 9.30 into Equation 9.29 yields</P>
<P ALIGN="CENTER"><IMG SRC="images/09-47d.jpg"></P>
<P>(9.31)
</P>
<P>From Equation 9.31, it follows directly that rotation about the origin is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/09-48d.jpg"></P>
<P>Q.E.D.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>A display of the amplitude vs. the phase of a waveform can be rotated by the introduction of a delay.<HR></FONT>
</BLOCKQUOTE>
<P>In the <I>Shape</I> class we implement the point rotation about any point using a translation to the center, followed by a rotation, followed by a translation back. The <I>Shape</I> class resides in the <I>lyon</I> package. The following code modifies the original point so that time does not have to be spent allocating and disposing of new point instances.</P>
<!-- CODE //-->
<PRE>
public void pointRotation(point p, point pc, double theta) {
// rotate point p about pc an amount of theta radians
// return the modified point
double c_theta = Math.cos(theta);
double s_theta = Math.sin(theta);
double tx = pc.x + (p.x - pc.x) * c_theta - (p.y - pc.y) * s_theta;
double ty = pc.y + (p.y - pc.y) * c_theta + (p.x - pc.x) * s_theta;
p.x = tx;
p.y = ty;
}
</PRE>
<!-- END CODE //-->
<P>The point rotation can be applied to images or graphic objects. Figure 9.17 shows a pinhole camera used for simulating a diffraction range finder in the DiffCAD program. As the camera is repositioned, it automatically pans to point toward the center of a diffraction grating.
</P>
<P><A NAME="Fig17"></A><A HREF="javascript:displayWindow('images/09-17.jpg',229,117 )"><IMG SRC="images/09-17t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-17.jpg',229,117)"><FONT COLOR="#000077"><B>Figure 9.17</B></FONT></A> A pinhole camera rotated about its center of focus.</P>
<H4 ALIGN="LEFT"><A NAME="Heading30"></A><FONT COLOR="#000077">Homogeneous Coordinate Transforms in 2-D</FONT></H4>
<P>So far we have see that translation, scaling, and rotation are
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-49d.jpg"></P>
<P ALIGN="CENTER"><IMG SRC="images/09-50d.jpg"></P>
<P>and
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-51d.jpg"></P>
<P>To concatenate several transforms into a single computational entity, we introduce homogeneous coordinates. This approach speeds the computation of combinations of several transformations by creating a single matrix against which points are multiplied. For this discussion, we follow [Foley et al.].
</P>
<P>With homogeneous coordinates we use <I>tuples</I> in 2-D: (<I>x</I>,<I>y</I>,<I>w</I>). Also, one of the coordinates must be nonzero (typically, <I>w</I> is nonzero).</P>
<P>Iff (if and only if)</P>
<P ALIGN="CENTER"><IMG SRC="images/09-52d.jpg"></P>
<P>(9.32)
</P>
<P>then <I>P’</I> and <I>P</I> represent the same point. That is, a linear combination of <I>P</I> does not alter the position of the original point. The proportionality factor, [alpha], is eliminated by computing the Cartesian coordinates of the homogeneous point:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-53d.jpg"></P>
<P>(9.33)
</P>
<P>The XYW homogeneous coordinate space, with the <I>w</I>=1 plane and point <I>P</I>(<I>x</I>,<I>y</I>,<I>w</I>), projects onto the <I>w</I>=1 plane.</P>
<P>Homogeneous coordinate transformations in 2-D space require a 3x3 matrix multiplication.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>If all you want to do is to translate, you are doing three multiplications and two additions for nothing!<HR></FONT>
</BLOCKQUOTE>
<P>The matrix form for the translation is as follows:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-54d.jpg"></P>
<P>(9.34)
</P>
<P>This is just like</P>
<P ALIGN="CENTER"><IMG SRC="images/09-55d.jpg"></P>
<P>with the exception of the <I>w</I> variable.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Multiplication by zero in Equation 9.34 takes the computer as long as the multiplication by a nonzero (unless we intercept this special case).<HR></FONT>
</BLOCKQUOTE>
<P>Some graphics textbooks premultiply rather than postmultiply by the column vectors. To convert between the forms, use transposition:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-56d.jpg"></P>
<P>(9.35)
</P>
<P>Expanding Equation 9.35 results in</P>
<P ALIGN="CENTER"><IMG SRC="images/09-57d.jpg"></P>
<P>(9.36)
</P>
<P>The Java implementation of Equation 9.34 can be found in the translation method in the <I>Mat3</I> class of the <I>lyon.ipl</I> package:</P>
<!-- CODE //-->
<PRE>
public Mat3 translation(point t) {
a = new double[3][3];
a[0][0] = 1;
a[1][1] = 1;
a[2][2] = 1;
a[0][2] = t.x;
a[1][2] = t.y;
return new Mat3(a);
}
</PRE>
<!-- END CODE //-->
<P>Suppose we write the following:
</P>
<!-- CODE SNIP //-->
<PRE>
public static void main(String args[]) {
Mat3 trans = Mat3.translation(new point(2,3));
trans.print();
}
</PRE>
<!-- END CODE SNIP //-->
<P>The output is as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
1 0 2
0 1 3
0 0 1
</PRE>
<!-- END CODE SNIP //-->
<P>Now we can perform the homogeneous coordinate transformations using matrix multiplications. We use this ability to concatenate many transformations into a single matrix representation. For example:
</P>
<!-- CODE //-->
<PRE>
public static void main(String args[]) {
Mat3 trans1 = Mat3.translation(new point(2,3));
Mat3 trans2 = Mat3.translation(new point(1,2));
Mat3 trans3 = trans1.multiply(trans2);
trans1.print();
System.out.println(“ * “ );
trans2.print();
System.out.println(“ = “);
trans3.print();
}
1 0 2
0 1 3
0 0 1
*
1 0 1
0 1 2
0 0 1
=
1 0 3
0 1 5
0 0 1
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="389-393.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="399-404.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright © <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -