📄 381-386.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=381-386//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="378-381.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="386-389.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The IYQ system is based on the idea that the human visual system requires crisp outlines, but that it can tolerate lower color bandwidths. This system reduces color bandwidth by low-pass filtering the I and Q color components. Further, because the eye is less sensitive to magenta than to orange, the I color component (orange-cyan) is given more bandwidth than the Q color component (green-magenta). Thus there are compelling human visual reasons for using the IYQ system (even in non-analog video compression systems) [Inglis].
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-33d.jpg"></P>
<P>(9.20)
</P>
<P>To convert from the IYQ space, we use the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-34d.jpg"></P>
<P>(9.21)
</P>
<P>For reasons of computational precision, we do not evaluate the matrix inverse expressed in Equation 9.21. Some books give the matrix and its inverse with three significant figures of resolution [Rogers]. We can get a much more precise answer if we allow Java to perform the inverse using the precision of a float or a double. This approach is particularly important, because we will use a floating-point format to store the pixels.</P>
<P>Some images (such as X-rays, MRI, and Hubble telescope pictures) contain more than 8 bits of color information per color plane. A floating-point format is ideal for storing this type of image. Although display buffers show only 8 bits per color, we need not introduce that limitation into our computations or data files.</P>
<H3><A NAME="Heading16"></A><FONT COLOR="#000077">The FloatImage Class</FONT></H3>
<P>The <I>FloatImage</I> class resides in the <I>lyon.ipl</I> package. Its purpose is to turn a <I>ProcessPlane</I> instance into three arrays of floats, which are needed to perform high-precision image processing. A reference to the <I>ProcessPlane</I> instance that is used to create the <I>FloatImage</I> is kept in internal private storage.</P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package lyon.ipl;
import java.net.URL;
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import futils.utils.*;
public class FloatImage {
public float r[];
public float g[];
public float b[];
public FloatImage(int l)
public FloatImage(ProcessPlane pp_)
public ProcessPlane makeProcessPlane()
public int getLength()
public int getHeight()
public int getWidth()
public float getRed(int i)
public float getGreen(int i)
public float getBlue(int i)
public float getAlpha(int i)
public float getRed(int x, int y)
public float getGreen(int x, int y)
public float getBlue(int x, int y)
public float getAlpha(int x, int y)
public void setPixel(int x, int y, float r_, float g_, float b_)
public void setPixel(int i, float r_, float g_, float b_)
public void printSize()
public float max(int i)
public float min(int i)
}
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
FloatImage fi;
ProcessPlane pp;
double red[];
double green[];
double blue[];
int l;
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the color components from a <I>FloatImage</I> instance, we use this code:</P>
<!-- CODE SNIP //-->
<PRE>
red = fi.r;
green = fi.g;
blue = fi.b;
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>After great deliberation, we have decided to make the RGB data structures public. The alternative is to fill code with <I>getArray</I> accessor methods. We are still not sure whether this was the right design choice. Typically, accessor methods are used to keep threads synchronized, but we have abandoned this approach. The resulting code is unsuitable for multithreading but is smaller, faster, and easier to understand.<HR></FONT>
</BLOCKQUOTE>
<P>To make an instance of a <I>FloatImage</I> with <I>l</I> pixels:</P>
<!-- CODE SNIP //-->
<PRE>
fi = new FloatImage(l);
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of a <I>FloatImage</I> by making a copy of a <I>ProcessPlane</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
fi = new FloatImage(pp);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Operations performed on the <I>FloatImage</I> instance do not alter the data of the <I>ProcessPlane</I> instances. All elements in the <I>ProcessPlane</I> instance were copied and type-converted during the copy process.<HR></FONT>
</BLOCKQUOTE>
<P>To turn an instance of a <I>FloatImage</I> into an instance of a <I>ProcessPlane</I>:</P>
<!-- CODE SNIP //-->
<PRE>
pp = fi.makeProcessPlane();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the number of pixels in the <I>FloatImage</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
l = fi.getLength();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the height and width of the <I>FloatImage</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
int h = fi.getHeight();
int w = fi.getWidth();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the red, green, blue, and alpha components in the <I>FloatImage</I> instance, treating all the arrays as 1-D arrays:</P>
<!-- CODE SNIP //-->
<PRE>
int i;
float r = fi.getRed(i);
float g = fi.getGreen(i);
float b = fi.getBlue(i);
float a = fi.getAlpha(i);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>The alpha channel is never kept in the <I>FloatImage</I> instance. Instead, the alpha channel is converted from the <I>ProcessPlane</I> on demand. The reason is that no <I>FloatImage</I> methods alter the alpha channel, so no floating-point version of the alpha channel is needed.<HR></FONT>
</BLOCKQUOTE>
<P>To get the red, green, blue, and alpha components in the <I>FloatImage</I> instance, treating all the arrays as 2-D arrays:</P>
<!-- CODE SNIP //-->
<PRE>
int x, y;
float r = fi.getRed(x, y);
float g = fi.getGreen(x, y);
float b = fi.getBlue(x, y);
float a = fi.getAlpha(x, y);
</PRE>
<!-- END CODE SNIP //-->
<P>To set a floating-point pixel using 2-D coordinates:
</P>
<!-- CODE SNIP //-->
<PRE>
float r, g, b;
int x, y;
fi.setPixel(x, y, r, g, b);
</PRE>
<!-- END CODE SNIP //-->
<P>To set a floating-point pixel using the 1-D internal order:
</P>
<!-- CODE SNIP //-->
<PRE>
fi.setPixel(i, r, g, b);
</PRE>
<!-- END CODE SNIP //-->
<P>To print the size of the array to <I>System.out</I>:</P>
<!-- CODE SNIP //-->
<PRE>
fi.printSize();
</PRE>
<!-- END CODE SNIP //-->
<P>To find the minimum- and maximum-amplitude color components located at position <I>i</I> in the 1-D internal order:</P>
<!-- CODE SNIP //-->
<PRE>
float intensity = fi.max(i);
float intensity = fi.min(i);
</PRE>
<!-- END CODE SNIP //-->
<H3><A NAME="Heading19"></A><FONT COLOR="#000077">The ColorConverter Class</FONT></H3>
<P>The <I>ColorConverter</I> class is an abstract class that resides in the <I>VS</I> package. The <I>ColorConverter</I> class is extended with implementations required for methods that convert from and to the RGB color space. Internally, <I>ColorConverter</I> provides a storage area for the <I>FloatImage</I> and <I>ProcessPlane</I> instances.</P>
<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package VS;
import java.awt.*;
import java.io.*;
import lyon.ipl.*;
public abstract class ColorConverter {
public ProcessPlane pp;
public FloatImage fi;
public ColorConverter(ProcessPlane pp_)
public abstract int[] fromRGB();
public abstract int[] toRGB();
public FloatImage getFloatImage()
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="378-381.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="386-389.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 + -