⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 386-389.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 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=386-389//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="381-386.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="389-393.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading21"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>A class that extends <I>ColorConverter</I> must implement the methods <I>fromRGB()</I> and <I>toRGB()</I>. A class that extends <I>ColorConverter</I> is used to convert a <I>ProcessPlane</I> instance (an RGB image) into an another color-space-encoded <I>FloatImage</I> instance. The <I>IYQ</I> class is an example of a class that extends <I>ColorConverter</I>:</P>
<!-- CODE SNIP //-->
<PRE>
package lyon.ipl;
import VS.*;
public class IYQ extends ColorConverter &#123;
</PRE>
<!-- END CODE SNIP //-->
<P>Recall that the RGB to IYQ conversion requires a matrix multiplication given by Equation 9.20:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-35d.jpg"></P>
<P>An implementation of Equation 9.20 follows:
</P>
<!-- CODE SNIP //-->
<PRE>
double A[][] = &#123;
     &#123; 0.299, 0.587,  0.114&#125;,
     &#123; 0.596,-0.274, -0.322&#125;,
     &#123; 0.211, 0.522,  0.311&#125;
     &#125;;
</PRE>
<!-- END CODE SNIP //-->
<P>To create instances of a matrix that knows how to invert itself and multiply itself by other matrices we use the <I>Mat3</I> class (discussed in the following section).</P>
<!-- CODE SNIP //-->
<PRE>
Mat3  rgb2iyqMat = new Mat3(A);
</PRE>
<!-- END CODE SNIP //-->
<P>The matrix inversion in Java is performed at instantiation. The results are much more precise than those found in most publications:
</P>
<!-- CODE SNIP //-->
<PRE>
Mat3  iyq2rgbMat = rgb2iyqMat.invert();
</PRE>
<!-- END CODE SNIP //-->
<P>The constructor calls the superclass, <I>ColorConverter</I>, which copies the <I>ProcessPlane</I> instance into a new <I>FloatImage</I> instance. This constructor is required of any class that is to extend <I>ColorConverter</I>.</P>
<!-- CODE SNIP //-->
<PRE>
public IYQ ( ProcessPlane pp_) &#123;
     super(pp_);
&#125;
</PRE>
<!-- END CODE SNIP //-->
<P>The following two methods are typical of any that implement a color-space conversion using a 3x3 matrix multiplication. This arrangement is common with color-space conversions, but several of them, such as polar coordinate color systems like HVS and HLS, do not perform the matrix multiplication of Equation 9.20.
</P>
<!-- CODE //-->
<PRE>
public int[] fromRGB() &#123;
double pel[];
float r, g, b;
      for (int i=0; i &lt; fi.getLength(); i&#43;&#43;) &#123;
           pel = rgb2iyqMat.multiply(fi.r[i],fi.g[i],fi.b[i]);
        fi.r[i] = (float) pel[0];
        fi.g[i] = (float) pel[1];
        fi.b[i] = (float) pel[2];
        pp.setPixel(i, (int) pel[0], (int) pel[1], (int)pel[2], 255);
      &#125;
      return(pp.pels);
&#125;
public int[] toRGB() &#123;
double pel[];
      for (int i=0; i &lt; fi.r.length; i&#43;&#43;) &#123;
           pel = iyq2rgbMat.multiply(fi.r[i],fi.g[i], fi.b[i]);
        fi.r[i] = (float) pel[0];
        fi.g[i] = (float) pel[1];
        fi.b[i] = (float) pel[2];
        pp.setPixel(i, (int) pel[0], (int) pel[1], (int)pel[2], 255);
      &#125;
      return(pp.pels);
 &#125;

&#125;
</PRE>
<!-- END CODE //-->
<H3><A NAME="Heading22"></A><FONT COLOR="#000077">The Mat3 Class</FONT></H3>
<P>The <I>Mat3</I> class is a public class that resides in the <I>lyon.ipl</I> package. Its purpose is to provide an optimized way to multiply nonsparse 3x3 matrices. It also acts as a test bed for experiments in using Maple (a symbolic manipulator) to generate optimized Java code.</P>
<P>The code generated by Maple is both human-readable and optimized for speed of execution. When used correctly, the code is also error-free. Maple can ease the programmer&#146;s burden in some cases. In general, the code that Maple generates requires human manipulation before it becomes usable as Java.</P>
<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package lyon.ipl;
public class Mat3 &#123;
public Mat3 (double a[][])
  public double [] [] getArray()
  public Mat3 invert()
  public Mat3 multiply(Mat3 bmat3)
  public double[] multiply(double v1, double v2, double v3 )
  public void print()
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading24"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>There is an example of class usage in the <I>IYQ</I> class. The <I>Mat3</I> class is designed for multiplying 3 &#215; 3 matrices by each other or by 3 &#215; 1s. It is designed for color-space conversion but is generally applicable to other tasks. The <I>Mat3</I> class also supports a fast 3 &#215; 3 matrix inversion. Suppose that the following variables are predefined:</P>
<!-- CODE SNIP //-->
<PRE>
double A[][] = &#123;
     &#123; 0.299, 0.587,  0.114&#125;,
     &#123; 0.596,-0.274, -0.322&#125;,
     &#123; 0.211, 0.522,  0.311&#125;
     &#125;;
Mat3  m3;
Mat3 m3inverse;
</PRE>
<!-- END CODE SNIP //-->
<P>To make a new instance of <I>Mat3</I>, use this code:</P>
<!-- CODE SNIP //-->
<PRE>
m3 = new Mat3(A);
</PRE>
<!-- END CODE SNIP //-->
<P>To find the inversion of an instance of <I>Mat3</I>:</P>
<!-- CODE SNIP //-->
<PRE>
m3inverse = m3.invert();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the double-precision 3x3 array stored in a <I>Mat3</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
A = m3.getArray();
</PRE>
<!-- END CODE SNIP //-->
<P>To multiply two <I>Mat3</I> instances:</P>
<!-- CODE SNIP //-->
<PRE>
Mat3 identity = m3.multiply(m3inverse);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>Floating-point error prevents the <I>Mat3</I> instance of the identity matrix from being exact, but it is close.<HR></FONT>
</BLOCKQUOTE>
<P>To multiply the 3x3 in <I>Mat3</I> by a 3x1 to obtain a 3x1 array of double (also optimized), use this code:</P>
<!-- CODE SNIP //-->
<PRE>
double r, g, b;
double v3[] = m3.multiply(r, g, b);
</PRE>
<!-- END CODE SNIP //-->
<P>To print a <I>Mat3</I> instance to <I>System.out PrintStream</I>:</P>
<!-- CODE SNIP //-->
<PRE>
m3.print();
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">Maple: The Java Gin Joint</FONT></H4>
<P>Maple is a language for symbolic manipulation [Char et al.]. Maple V was used to generate optimized Java code for implementing matrix manipulation in the <I>Mat3</I> class. This is an interesting twist in Java that we have not seen in any other Java books.</P>
<P>The cotton gin is a symbol of the beginning of the industrial revolution. Before the industrial revolution, all work was performed by hand, and assembly-line methods were unknown. Perhaps software is also in its preindustrial-revolution days. We have yet to formulate automatic methods for the generation of software except in special cases. Matrix manipulation is one of those cases (and there are few others).</P>
<P>In Maple, the following code will generate the Java source needed to generate a time-optimal 3x3 matrix inversion:</P>
<!-- CODE SNIP //-->
<PRE>
1.     with(linalg):
2.     readlib(C):
3.     a =array(0..2,0..2,[]):
4.     b =array(0..2,0..2,[]):
5.     b =inverse(matrix(a)):
6.     C(b,optimized);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="381-386.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="389-393.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <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 + -