📄 image analysis.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0093)http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html -->
<HTML><HEAD><TITLE>Image Analysis</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=exclude name=collection>
<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<CENTER><A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/JAITOC.fm.html"><IMG
alt=Contents src="Image Analysis.files/contents.gif"></A> <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Geom-image-manip.doc.html"><IMG
alt=Previous src="Image Analysis.files/previous.gif"></A> <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Graphics.doc.html"><IMG
alt=Next src="Image Analysis.files/next.gif"></A>
<P><FONT size=5><I>Programming in Java Advanced Imaging</I></FONT> </CENTER><BR>
<CENTER><A name=55364>
<TABLE width="90%" border=0>
<TBODY>
<TR>
<TD align=right><FONT size=3>C H A P T E R</FONT><FONT size=7><IMG
src="Image Analysis.files/sm-space.gif">9</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<CENTER><A name=55366>
<TABLE width="90%" border=0>
<TBODY>
<TR>
<TD align=right>
<HR noShade SIZE=7>
<FONT size=6>Image Analysis</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<BLOCKQUOTE>
<P><BR><BR><BR>
<P><FONT size=7><B>T</B></FONT>HIS chapter describes the JAI API image
analysis operators.
<P><A name=50856>
<H2>9.1 <IMG src="Image Analysis.files/space.gif">Introduction</H2></A>The JAI
API image analysis operators are used to directly or indirectly extract
information from an image. The JAI API supports the following image analysis
functions:
<P>
<UL>
<LI>Finding the mean value of an image region
<P></P></LI></UL>
<UL>
<LI>Finding the minimum and maximum values in an image (extrema)
<P></P></LI></UL>
<UL>
<LI>Producing a histogram of an image
<P></P></LI></UL>
<UL>
<LI>Detecting edges in an image
<P></P></LI></UL>
<UL>
<LI>Performing statistical operations
<P></P></LI></UL><A name=54841>
<H2>9.2 <IMG src="Image Analysis.files/space.gif">Finding the Mean Value of an
Image Region</H2></A>The <CODE>Mean</CODE> operation scans a specified region
of an image and computes the image-wise mean pixel value for each band within
the region. The region of interest does not have to be a rectangle. If no
region is specified (null), the entire image is scanned to generate the
histogram. The image data pass through the operation unchanged.
<P>The <CODE>mean</CODE> operation takes one rendered source image and three
parameters:
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TH><A name=54846>Parameter </A>
<TH><A name=54848>Type </A>
<TH><A name=54850>Description </A>
<TR vAlign=top>
<TD><A name=54852>roi</A><BR>
<TD><A name=54854>ROI</A><BR>
<TD><A name=54856>The region of the image to scan. A null value means
the whole image.</A><BR>
<TR vAlign=top>
<TD><A name=54858>xPeriod</A><BR>
<TD><A name=54860>Integer</A><BR>
<TD><A name=54862>The horizontal sampling rate. May not be less than
1.</A><BR>
<TR vAlign=top>
<TD><A name=54864>yPeriod</A><BR>
<TD><A name=54866>Integer</A><BR>
<TD><A name=54868>The vertical sampling rate. May not be less than
1.</A><BR></TR></TBODY></TABLE>
<P>The region of interest (ROI) does not have to be a rectangle. It may be
<CODE>null</CODE>, in which case the entire image is scanned to find the
image-wise mean pixel value for each band.
<P>The set of pixels scanned may be reduced by specifying the
<CODE>xPeriod</CODE> and <CODE>yPeriod</CODE> parameters, which define the
sampling rate along each axis. These variables may not be less than 1.
However, they may be <CODE>null</CODE>, in which case the sampling rate is set
to 1; that is, every pixel in the ROI is processed.
<P>The image-wise mean pixel value for each band may be retrieved by calling
the <CODE>getProperty</CODE> method with <CODE>"mean"</CODE> as the property
name. The return value has type <CODE>java.lang.Number[#bands]</CODE>.
<P><A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html#56522">Listing
9-1</A> shows a partial code sample of finding the image-wise mean pixel value
of an image in the rendered mode.
<P><CAPTION><FONT size=-1><B><A name=56522>
<CENTER><FONT size=-1><B><I>Listing 9-1 </I><IMG
src="Image Analysis.files/sm-blank.gif" border=0> Finding the Mean Value of an
Image Region</B></FONT></CENTER></A>
<P></B></FONT></CAPTION>
<HR>
<TR valign="top"><TD><PRE> // Set up the parameter block for the source image and
// the three parameters.
ParameterBlock pb = new ParameterBlock();
pb.addSource(im); // The source image
pb.add(null); // null ROI means whole image
pb.add(1); // check every pixel horizontally
pb.add(1); // check every pixel vertically
</PRE><TR valign="top"><TD><PRE> // Perform the mean operation on the source image.
RenderedImage meanImage = JAI.create("mean", pb, null);
</PRE><TR valign="top"><TD><PRE> // Retrieve and report the mean pixel value.
double[] mean = (double[])meanImage.getProperty("mean");
System.out.println("Band 0 mean = " + mean[0]);
</PRE>
<HR>
<P><A name=54907>
<H2>9.3 <IMG src="Image Analysis.files/space.gif">Finding the Extrema of an
Image</H2></A>The <CODE>Extrema</CODE> operation scans a specific region of a
rendered image and finds the image-wise minimum and maximum pixel values for
each band within that region of the image. The image pixel data values pass
through the operation unchanged. The <CODE>extrema</CODE> operation can be
used to obtain information to compute the scale and offset factors for the
amplitude rescaling operation (see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-enhance.doc.html#76502">Section
7.4, "Amplitude Rescaling</A>").
<P>The region-wise maximum and minimum pixel values may be obtained as
properties. Calling the <CODE>getProperty</CODE> method on this operation with
<CODE>"extrema"</CODE> as the property name retrieves both the region-wise
maximum and minimum pixel values. Calling it with <CODE>"maximum"</CODE> as
the property name retrieves the region-wise maximum pixel value, and with
<CODE>"minimum"</CODE> as the property name retrieves the region-wise minimum
pixel value.
<P>The return value for <CODE>extrema</CODE> has type
<CODE>double[2][#bands]</CODE>, and those for <CODE>maximum</CODE> and
<CODE>minimum</CODE> have type <CODE>double[#bands]</CODE>.
<P>The region of interest (ROI) does not have to be a rectangle. It may be
<CODE>null</CODE>, in which case the entire image is scanned to find the
image-wise maximum and minimum pixel values for each band.
<P>The <CODE>extrema</CODE> operation takes one rendered source image and
three parameters:
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TH><A name=54912>Parameter </A>
<TH><A name=54914>Type </A>
<TH><A name=54916>Description </A>
<TR vAlign=top>
<TD><A name=54918>roi</A><BR>
<TD><A name=54920>ROI</A><BR>
<TD><A name=54922>The region of the image to scan.</A><BR>
<TR vAlign=top>
<TD><A name=54924>xPeriod</A><BR>
<TD><A name=54926>Integer</A><BR>
<TD><A name=54928>The horizontal sampling rate (may not be less than
1).</A><BR>
<TR vAlign=top>
<TD><A name=54930>yPeriod</A><BR>
<TD><A name=54932>Integer</A><BR>
<TD><A name=54934>The vertical sampling rate (may not be less than
1).</A><BR></TR></TBODY></TABLE>
<P>The set of pixels scanned may be further reduced by specifying the
<CODE>xPeriod</CODE> and <CODE>yPeriod</CODE> parameters that represent the
sampling rate along each axis. These variables may not be less than 1.
However, they may be <CODE>null</CODE>, in which case the sampling rate is set
to 1; that is, every pixel in the ROI is processed.
<P><A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html#56559">Listing
9-2</A> shows a partial code sample of using the <CODE>extrema</CODE>
operation to obtain both the image-wise maximum and minimum pixel values of
the source image.
<P><CAPTION><FONT size=-1><B><A name=56559>
<CENTER><FONT size=-1><B><I>Listing 9-2 </I><IMG
src="Image Analysis.files/sm-blank.gif" border=0> Finding the Extrema of an
Image </B></FONT></CENTER></A>
<P></B></FONT></CAPTION>
<HR>
<TR valign="top"><TD><PRE> // Set up the parameter block for the source image and
// the constants
ParameterBlock pb = new ParameterBlock();
pb.addSource(im); // The source image
pb.add(roi); // The region of the image to scan
pb.add(50); // The horizontal sampling rate
pb.add(50); // The vertical sampling rate
</PRE><TR valign="top"><TD><PRE> // Perform the extrema operation on the source image
RenderedOp op = JAI.create("extrema", pb);
</PRE><TR valign="top"><TD><PRE> // Retrieve both the maximum and minimum pixel value
double[][] extrema = (double[][]) op.getProperty("extrema");
</PRE>
<HR>
<P><A name=54836>
<H2>9.4 <IMG src="Image Analysis.files/space.gif">Histogram
Generation</H2></A>An image histogram is an analytic tool used to measure the
amplitude distribution of pixels within an image. For example, a histogram can
be used to provide a count of the number of pixels at amplitude 0, the number
at amplitude 1, and so on. By analyzing the distribution of pixel amplitudes,
you can gain some information about the visual appearance of an image. A
high-contrast image contains a wide distribution of pixel counts covering the
entire amplitude range. A low contrast image has most of the pixel amplitudes
congregated in a relatively narrow range.
<P>Usually, the wider histogram represents a more visually-appealing image.
<P><A name=51190>
<HR>
<CENTER><IMG src="Image Analysis.files/Analysis.doc.anc.gif"></CENTER>
<HR>
</A><A name=51191>
<CENTER><FONT size=-1><B><I>Figure 9-1 </I><IMG
src="Image Analysis.files/sm-blank.gif" border=0> Example
Histograms</B></FONT></CENTER></A>
<P>The primary tasks needed to perform a histogram operation are as follows:
<P>
<UL>1. Create a <CODE>Histogram</CODE> object, which specifies the type of
histogram to be generated.
<P>2. Create a <CODE>Histogram</CODE> operation with the required parameters
or create a <CODE>ParameterBlock</CODE> with the parameters and pass it to
the <CODE>Histogram</CODE> operation.
<P>3. Read the histogram data stored in the object. The data consists of:
<P>
<UL>
<UL>
<LI>Number of bands in the histogram</LI></UL>
<UL>
<LI>Number of bins for each band of the image</LI></UL>
<UL>
<LI>Lowest value checked for each band</LI></UL>
<UL>
<LI>Highest value checked for each band</LI></UL></UL></UL><A name=55111>
<H3>9.4.1 <IMG src="Image Analysis.files/space.gif">Specifying the
Histogram</H3></A>The <CODE>Histogram</CODE> object accumulates the histogram
information. A histogram counts the number of image samples whose values lie
within a given range of values, or "bins." The source image may be of any data
type.
<P>The <CODE>Histogram</CODE> contains a set of bins for each band of the
image. These bins hold the information about gray or color levels. For
example, to take the histogram of an eight-bit grayscale image, the
<CODE>Histogram</CODE> might contain 256 bins. When reading the
<CODE>Histogram</CODE>, bin 0 will contain the number of 0's in the image, bin
1 will contain the number of 1's, and so on.
<P>The <CODE>Histogram</CODE> need not contain a bin for every possible value
in the image. It is possible to specify the lowest and highest values that
will result in a bin count being incremented. It is also possible to specify
fewer bins than the number of levels being checked. In this case, each bin
will hold the count for a range of values. For example, for a
<CODE>Histogram</CODE> with only four bins used with an 8-bit grayscale image,
the number of occurrences of values 0 through 63 will be stored in bin 0,
occurrences of values 64 through 127 will be stored in bin 1, and so on.
<P>The <CODE>Histogram</CODE> object takes three parameters:
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TH><A name=55182>Parameter </A>
<TH><A name=55184>Description </A>
<TR vAlign=top>
<TD><A name=55186>numBins</A><BR>
<TD><A name=55188>An array of ints, each element of which specifies the
number of bins to be used for one band of the image. The number of
elements in the array must match the number of bands in the
image.</A><BR>
<TR vAlign=top>
<TD><A name=55190>lowValue</A><BR>
<TD><A name=55192>An array of floats, each element of which specifies
the lowest gray or color level that will be checked for in one band of
the image. The number of elements in the array must match the number of
bands in the image.</A><BR>
<TR vAlign=top>
<TD><A name=55194>highValue</A><BR>
<TD><A name=55196>An array of floats, each element of which specifies
the highest gray or color level that will be checked for in one band of
the image. The number of elements in the array must match the number of
bands in the image.</A><BR></TR></TBODY></TABLE>
<P>For an example histogram, see <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html#56595">Listing
9-3 on page 315</A>.
<P>
<TABLE border=0>
<TBODY>
<TR>
<TD><IMG src="Image Analysis.files/cistine.gif"></TD>
<TD>
<HR>
<B>API:</B> <CODE>javax.media.jai.Histogram </CODE>
<HR>
</TD></TR></TBODY></TABLE><PRE><UL>
<LI>Histogram(int[] numBins, float[] lowValue, float[] highValue)
<P></P></LI></UL></PRE>
<DL><A name=55117>
<DT>
<DD>constructs a <CODE>Histogram</CODE> that may be used to accumulate data
within a given range for each band of an image. The legal pixel range and
the number of bins may be controlled separately.
<P>
<TABLE cellPadding=3 border=3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -