📄 404-406.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=404-406//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="399-404.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="406-410.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading31"></A><FONT COLOR="#000077">Applications of Affine Transforms</FONT></H4>
<P>In this section we show examples of the use of affine transforms in DiffCAD for manipulating image data. In all the cases, the <I>ProcessPlane</I> class has been modified to permit the use of a 3x3 matrix transform to process the output coordinates of the image. The output coordinates are multiplied by the matrix transform centered on the image coordinates. The result of the multiplication is used to resample the input image. No filtering is performed, so we can expect aliasing effects. The heart of the transformation is a method called <I>xform</I>:</P>
<!-- CODE SNIP //-->
<PRE>
public void xform(Mat3 transform) {
int w = getWidth();
int h = getHeight();
int xc = w/2;
int yc = h/2;
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>xform</I> method takes a precomputed transformation matrix in the form of an instance of the <I>Mat3</I> class. The height and width are obtained from the input image. The output image is stored in an instance of <I>ProcessPlane</I>, pp:</P>
<!-- CODE SNIP //-->
<PRE>
ProcessPlane pp = new ProcessPlane(w,h);
</PRE>
<!-- END CODE SNIP //-->
<P>The result of the 3x3 matrix multiplication by a 3x1 is a 3x1. The result is stored in an array called <I>p</I>:</P>
<!-- CODE SNIP //-->
<PRE>
double p[] = new double [3];
int pixel;
int xp, yp;
</PRE>
<!-- END CODE SNIP //-->
<P>We follow the idea of [Expeset] and start to scan the output image using coordinates that bias the center of the image toward the origin. This technique permits rotation about the center of the image rather than the origin (the upper-left corner of the image in the Java AWT).
</P>
<!-- CODE //-->
<PRE>
for (int x = -xc; x < xc; x++)
for (int y=-yc; y < yc; y++) {
p=transform.multiply(x,y,1);
xp = (int) p[0]+xc;
yp = (int) p[1]+yc;
if ((xp < w) && (yp < h) && (xp >= 0) && (yp >= 0)) {
pixel = getPixel(xp, yp);
pp.setPixel(x+xc,y+yc,pixel);
}
}
pels = pp.pels;
}
</PRE>
<!-- END CODE //-->
<P>The <I>xform</I> method permits implementation of any of the transforms by creating a 3x3 matrix and calling <I>xform</I>. An example is the <I>ProcessPlane</I> method <I>turn</I>:</P>
<!-- CODE SNIP //-->
<PRE>
public void turn(double degrees) {
double pion180 = Math.PI / 180.0;
double theta = degrees * pion180;
xform(Mat3.rotation(theta));
}
</PRE>
<!-- END CODE SNIP //-->
<P>Another example is the <I>ProcessPlane</I> method <I>zoom</I>:</P>
<!-- CODE SNIP //-->
<PRE>
public void zoom(double percentage) {
xform(Mat3.scaling(new point(percentage,percentage)));
}
</PRE>
<!-- END CODE SNIP //-->
<P>Finally, we implement the shear in <I>x</I> and <I>y</I> using the following:</P>
<!-- CODE SNIP //-->
<PRE>
public void shearx(double shx) {
xform(Mat3.shear(new point(shx,0)));
}
public void sheary(double shy) {
xform(Mat3.shear(new point(0,shy)));
}
</PRE>
<!-- END CODE SNIP //-->
<P>The results of a shear in <I>x</I> and a shear in <I>y</I> are shown in Figure 9.22.</P>
<P><A NAME="Fig22"></A><A HREF="javascript:displayWindow('images/09-22.jpg',397,214 )"><IMG SRC="images/09-22t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-22.jpg',397,214)"><FONT COLOR="#000077"><B>Figure 9.22</B></FONT></A> Shear in x and shear in y.</P>
<P>Instead of making a new image, we can use the input image as the canvas for our output. We can then reprocess the image using the result. This is known as a <I>feedback loop</I>. Many cool effects are based on feedback. Figure 9.23 shows zoom being used with feedback. The only modification is to add a new <I>xform</I> method called <I>xformfeedback</I> to <I>ProcessPlane</I>. The <I>xformfeedback</I> method is just like the <I>xform</I> method except for one important difference:</P>
<!-- CODE SNIP //-->
<PRE>
for (int x = -xc; x < xc; x++)
for (int y=-yc; y < yc; y++) {
p=transform.multiply(x,y,1);
xp = (int) p[0]+xc;
yp = (int) p[1]+yc;
if ((xp < w) && (yp < h) && (xp >= 0) && (yp >= 0)) {
pixel = getPixel(xp, yp);
</PRE>
<!-- END CODE SNIP //-->
<P><A NAME="Fig23"></A><A HREF="javascript:displayWindow('images/09-23.jpg',402,138 )"><IMG SRC="images/09-23t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-23.jpg',402,138)"><FONT COLOR="#000077"><B>Figure 9.23</B></FONT></A> Many cool effects are based on feedback.</P>
<P>At this point in the code, <I>xform</I> would set the pixel on a <I>ProcessPlane</I> instance. Instead, <I>xformfeedback</I> uses its own.</P>
<!-- CODE SNIP //-->
<PRE>
setPixel(x+xc,y+yc,pixel);
}
}
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="399-404.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="406-410.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 + -