📄 355-361.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=355-361//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch08/352-354.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="361-365.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 9<BR>Image Processing in Java
</FONT></H2>
<P ALIGN="RIGHT">The worth of a book is to be measured by what you can carry away from it.
</P>
<P ALIGN="RIGHT"><I>—James Bryce</I></P>
<P ALIGN="RIGHT">Save the mandrills, collect the whole set.</P>
<P ALIGN="RIGHT"><I>—DL</I></P>
<P>This chapter covers the computation of the histogram of an image. We follow this with a derivation of the basis for the 2-D Fast Fourier Transform (2-D FFT) and a summary of a class that implements the 2-D FFT. We show how to use the FFT to perform high- and low-pass filtering.</P>
<P>The high-pass filtering of the FFT is used to create edges, which are linked using a raster to vector converter. The raster to vector converter inputs an edge-detected image and outputs a series of line segments that can be drawn to the screen and saved as a PICT file.</P>
<P>We also cover color-space conversions and elementary 2-D rotation and scaling.</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">The Histogram</FONT></H3>
<P>The <I>histogram</I> of an image is the probability mass function (PMF) of the pixel intensities. The PMF shows the statistical frequency of occurrence for an event. Thus, the PMF is computed by counting the number of times an event (a particular intensity) occurs in the data and then dividing by the total number of pixels in the image.</P>
<P>For example, suppose an image consists of a 1-D array given by the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-01d.jpg"></P>
<P>(9.1)
</P>
<P>The PMF is computed, and the array is then expressed as an event with its associated PMF number:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-02d.jpg"></P>
<P>(9.2)
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>The PMF is a discrete probability distribution function (PDF). Like the PDF, the PMF numbers will always sum to 1.<HR></FONT>
</BLOCKQUOTE>
<P>Naturally, the image arrays are much larger than that given in Equation 9.1. Furthermore, the array list shown in Equation 9.2 is typically shown as a bar chart. An example histogram is shown in Figure 9.1.
</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/09-01.jpg',300,457 )"><IMG SRC="images/09-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-01.jpg',300,457)"><FONT COLOR="#000077"><B>Figure 9.1</B></FONT></A> An example histogram.</P>
<P>The histogram of Figure 9.1 is shown for 255 intensities in red, green, blue (RGB), and intensity (I). The intensity is computed by averaging the RGB components and truncating to the nearest integer. The Histogram frame extends the <I>PictFrame</I> and, in doing so, saves the histogram as a PICT file (for editing). An example is shown in Figure 9.2.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/09-02.jpg',293,161 )"><IMG SRC="images/09-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/09-02.jpg',293,161)"><FONT COLOR="#000077"><B>Figure 9.2</B></FONT></A> A section of the Histogram frame’s PICT output.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Once the histogram is saved as PICT, the fonts can be changed so that they are no longer bitmapped. In this case, they are selected as Times Roman.<HR></FONT>
</BLOCKQUOTE>
<P>A code fragment from the <I>Histogram</I> class in the <I>lyon.ipl</I> package shows how to implement the display of Figure 9.1:</P>
<!-- CODE //-->
<PRE>
package lyon.ipl;
import java.awt.*;
import java.awt.image.*;
import gui.*;
import lyon.dclap.*;
class Histogram extends PictFrame {
public int red[] = new int[256];
public int green[] = new int[256];
public int blue[] = new int[256];
public int intensity[] = new int[256];
</PRE>
<!-- END CODE //-->
<P>The constructor for the <I>Histogram</I> class takes a <I>PixelPlane</I> instance as an argument:</P>
<!-- CODE SNIP //-->
<PRE>
public Histogram(PixelPlane p) {
...
</PRE>
<!-- END CODE SNIP //-->
<P><I>Histogram</I> uses the RGB values to act as indexes into three arrays of 256 integers.</P>
<!-- CODE SNIP //-->
<PRE>
for (int i=0; i<tp; i++) {
red[p.getRed(i)]+=1;
green[p.getGreen(i)]+=1;
blue[p.getBlue(i)]+=1;
}
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>Histogram</I> constructor then computes the intensity by taking the truncated average of the three colors.</P>
<!-- CODE SNIP //-->
<PRE>
for (int i=0; i<intensity.length; i++) {
intensity[i] = (red[i]+green[i]+blue[i])/3;
}
</PRE>
<!-- END CODE SNIP //-->
<P>The rest of the code is devoted to normalization and display.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>CD-ROM: </B>The full source code for <I>Histogram</I> is available on the book’s CD-ROM.<HR></FONT>
</BLOCKQUOTE>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">The 2-D DFT</FONT></H3>
<P>Recall the 1-D DFT from Chapter 6:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-03d.jpg"></P>
<P>The inverse DFT is given by the following:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-04d.jpg"></P>
<P>Suppose that we have a 2-D array of uniformly sampled and quantized data:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-05d.jpg"></P>
<P>where
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-06d.jpg"></P>
<P>The terms <I>W</I> and <I>H</I> are the width and height of the image in pixels.</P>
<P>The 2-D Discrete Fourier Transform (2-D DFT) is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/09-07d.jpg"></P>
<P>(9.3)
</P>
<P>The inverse 2-D DFT (2-D IDFT) is given by</P>
<P ALIGN="CENTER"><IMG SRC="images/09-08d.jpg"></P>
<P>(9.4)
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>The (1/<I>WH</I>) term is not present in the IDFT, nor is the negative sign in the exponent.<HR></FONT>
</BLOCKQUOTE>
<P>We introduce a notation (following [Gonzalez et al.]) that uses a symbol, called the double arrow, to shorten the expressions in Equations 9.3 and 9.4 to the following:
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-09d.jpg"></P>
<P>(9.4a)
</P>
<P>To turn the 2-D DFT into a 2-D FFT, we use the <I>separability</I> property to break the 2-D DFT into two fast 1-D FFTs. The exponential function’s separability is due to the laws of exponents, namely, <I>e</I><SUP>a</SUP> <I>e</I><SUP>b</SUP> = <I>e</I><SUP>(a+b)</SUP>.</P>
<P>To employ the separability property, we factor Equation 9.3 into the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-10d.jpg"></P>
<P>(9.5)
</P>
<P>Similarly, we factor the 2-D IDFT from Equation 9.4 into the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-11d.jpg"></P>
<P>(9.6)
</P>
<P>The separability property means that the 2-D DFT can be computed by finding the 1-D DFT on the rows of the image and then finding the 1-D DFT on the columns. This means that we can use the 1-D DFT (and FFT) code from Chapter 6 to help perform the 2-D FFT.</P>
<P>Our implementation of Equation 9.5 transforms each row, placing the outcome in a complex array whose dimensions match those of the original image. Then we transform each column of the complex array. Thus, the 1-D DFT is performed on each row and again on each column.</P>
<P>Recall that the centering of Chapter 6 used</P>
<P ALIGN="CENTER"><IMG SRC="images/09-12d.jpg"></P>
<P>to cause a shift in the PSD. This comes about as a result of the time-shift theorem that states that in the frequency domain, spatial translation causes an added linear phase with slope proportional to the shift so that
</P>
<P ALIGN="CENTER"><IMG SRC="images/09-13d.jpg"></P>
<P>(9.7)
</P>
<P>The dual of Equation 9.7 is</P>
<P ALIGN="CENTER"><IMG SRC="images/09-14d.jpg"></P>
<P>(9.8)
</P>
<P>Where the left-hand side of Equation 9.7 is the Fourier transform of the right-hand side (using double arrow notation). Thus, a positional shift in the input plane causes a phase shift in the output plane. To put it another way, a positional shift in the time domain causes a phase shift in the frequency domain. This makes sense if we think of a sine wave being shifted in time. Relative to the unshifted sine wave, the shifted sine wave has a different phase. We represent a phase shift by multiplying by the complex exponential. To center the frequency on the 2-D DFT, we shift the frequency bins by <I>W</I>/2 and <I>H</I>/2. Thus, Equation 9.8 becomes</P>
<P ALIGN="CENTER"><IMG SRC="images/09-15d.jpg"></P>
<P>(9.9)
</P>
<P>This simplifies to</P>
<P ALIGN="CENTER"><IMG SRC="images/09-16d.jpg"></P>
<P>(9.10)
</P>
<P>By Euler’s relation,</P>
<P ALIGN="CENTER"><IMG SRC="images/09-17d.jpg"></P>
<P>and because <I>x,y</I> are integers, we get the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-18d.jpg"></P>
<P>(9.11)
</P>
<P>Substituting Equation 9.11 into Equation 9.10 results in the following:</P>
<P ALIGN="CENTER"><IMG SRC="images/09-19d.jpg"></P>
<P>(9.12)
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch08/352-354.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="361-365.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 + -