📄 329-331.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:An Introduction to Image Processing</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=7//-->
<!--PAGES=329-331//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="323-329.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch08/333-336.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">Class Implementation: The edge Method</FONT></H4>
<P>The <I>edge</I> method is probably one of the most complex image processing methods in the <I>ProcessPlane</I> class. The basic idea behind the <I>edge</I> method is to run through the following steps:</P>
<!-- CODE SNIP //-->
<PRE>
1. Compute the average intensity<I>, a</I>, for pixel row, y.
2. Find the pixel, <I>xr</I>, that exceeds <I>a.</I>
3. Find the very next pixel, <I>xl</I>, that does not exceed <I>a</I>.
4. Compute the average of <I>xr</I> and <I>xl</I> and call it <I>xa</I>.
5. Store <I>xa,y</I> as an edge point.
6. Increment <I>y</I>.
7. If <I>y</I> > <I>imageHeight</I> then stop, else goto 1.
</PRE>
<!-- END CODE SNIP //-->
<P>This type of ad hoc algorithm will always find the leftmost bright edge for a well-defined stripe. At the same time, it finds the centroid of the stripe. As the stripe gets closer to the left of the image, the program runs faster (because it has to search fewer pixels to find the stripe). Thus, good lighting and camera positioning are needed to make this algorithm run fast. The Java implementation of the <I>edge</I> method follows:</P>
<!-- CODE //-->
<PRE>
public ProcessPlane edge() {
ProcessPlane pp = new ProcessPlane(getWidth(), getHeight());
int r,a;
int average; // average intensity
for (int y = 0; y < getHeight(); y++)
new_line: {
average = 0;
for (int x =0 ; x < getWidth(); x++)
average = average + getRed (x,y);
average = average / getWidth();
for (int x =0 ; x < getWidth(); x++) {
r = getRed (x,y);
a = getAlpha(x,y);
if (r > average) {
int start=x;
for (int i=x;i < getWidth(); i++) {
r = getRed (i,y);
if (r < average) {
pp.setPixel(
start + (i - start) / 2,
y,255,255,255,a);
break new_line;
}
}
}
}
}
return pp;
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="323-329.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch08/333-336.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 + -