📄 image manipulation.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0103)http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-manipulation.doc.html -->
<HTML><HEAD><TITLE>Image Manipulation</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content=reference 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 Manipulation.files/contents.gif"></A> <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Color.doc.html"><IMG
alt=Previous src="Image Manipulation.files/previous.gif"></A> <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Image-enhance.doc.html"><IMG
alt=Next src="Image Manipulation.files/next.gif"></A>
<P><FONT size=5><I>Programming in Java Advanced Imaging</I></FONT> </CENTER><BR>
<CENTER><A name=47227>
<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 Manipulation.files/sm-space.gif">6</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<CENTER><A name=47285>
<TABLE width="90%" border=0>
<TBODY>
<TR>
<TD align=right>
<HR noShade SIZE=7>
<FONT size=6>Image Manipulation</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<BLOCKQUOTE>
<P><BR><BR><BR>
<P><FONT size=7><B>T</B></FONT>HIS chapter describes the basics of
manipulating images to prepare them for further processing.
<P><A name=50856>
<H2>6.1 <IMG src="Image Manipulation.files/space.gif">Introduction</H2></A>The
JAI image manipulation objects and methods are used to enhance and
geometrically modify images and to extract information from images. Image
manipulation includes:
<P>
<UL>
<LI>Region of interest (ROI) control
<P></P></LI></UL>
<UL>
<LI>Relational operators
<P></P></LI></UL>
<UL>
<LI>Logical operators
<P></P></LI></UL>
<UL>
<LI>Arithmetic operators
<P></P></LI></UL>
<UL>
<LI>Dithering
<P></P></LI></UL>
<UL>
<LI>Clamping pixel values
<P></P></LI></UL>
<UL>
<LI>Band copy
<P></P></LI></UL><A name=51458>
<H2>6.2 <IMG src="Image Manipulation.files/space.gif">Region of Interest
Control</H2></A>Typically, any image enhancement operation takes place over
the entire image. While the image enhancement operation may improve portions
of an image, other portions of the image may lose detail. You usually want
some way of limiting the enhancement operation to specific regions of the
image.
<P>To restrict the image enhancement operations to specific regions of an
image, a region-of-interest mask is created. A region of interest (ROI) is
conceptually a mask of true or false values. The ROI mask controls which
source image pixels are to be processed and which destination pixels are to be
recorded.
<P>JAI supports two different types of ROI mask: a Boolean mask and a
threshold value. The <CODE>ROIShape</CODE> class uses a Boolean mask, which
allows operations to be performed quickly and with compact storage. The
<CODE>ROI</CODE> class allows the specification of a threshold value; pixel
values greater than or equal to the threshold value are included in the ROI.
Pixel values less than the threshold are excluded.
<P>The region of interest is usually defined using a <CODE>ROIShape</CODE>,
which stores its area using the <CODE>java.awt.Shape</CODE> classes. These
classes define an area as a geometrical description of its outline. The
<CODE>ROI</CODE> class stores an area as a single-banded image.
<P>An ROI can be attached to an image as a property. See <A
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Properties.doc.html#47285">Chapter
11, "Image Properties</A>."
<P><A name=60492>
<H3>6.2.1 <IMG src="Image Manipulation.files/space.gif">The ROI
Class</H3></A>The <CODE>ROI</CODE> class stores an area as a grayscale
(single-banded) image. This class represents region information in image form,
and can thus be used as a fallback where a <CODE>Shape</CODE> representation
is unavailable. Inclusion and exclusion of pixels is defined by a threshold
value. Source pixel values greater than or equal to the threshold value
indicate inclusion in the ROI and are processed. Pixel values less than the
threshold value are excluded from processing.
<P>Where possible, subclasses such as <CODE>ROIShape</CODE> are used since
they provide a more compact means of storage for large regions.
<P>The <CODE>getAsShape()</CODE> method may be called optimistically on any
instance of <CODE>ROI</CODE>. However, it may return null to indicate that a
<CODE>Shape</CODE> representation of the <CODE>ROI</CODE> is not available. In
this case, <CODE>getAsImage()</CODE> should be called as a fallback.
<P>
<TABLE border=0>
<TBODY>
<TR>
<TD><IMG src="Image Manipulation.files/cistine.gif"></TD>
<TD>
<HR>
<B>API:</B> <CODE>javax.media.jai.ROI </CODE>
<HR>
</TD></TR></TBODY></TABLE><PRE><UL>
<LI>ROI(RenderedImage im)
<P></P></LI></UL></PRE>
<DL><A name=51428>
<DT>
<DD>constructs an <CODE>ROI</CODE> object from a <CODE>RenderedImage</CODE>.
The inclusion threshold is taken to be halfway between the minimum and
maximum sample values specified by the image's <CODE>SampleModel</CODE>.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD><EM>Parameters</EM>:
<P></P>
<TD><CODE>im</CODE>
<P></P>
<TD>A single-banded <CODE>RenderedImage</CODE>.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>ROI(RenderedImage im, int threshold)
<P></P></LI></UL></PRE>
<DL><A name=51437>
<DT>
<DD>constructs an <CODE>ROI</CODE> object from a <CODE>RenderedImage</CODE>.
The inclusion <CODE>threshold</CODE> is specified explicitly.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD rowSpan=2><EM>Parameters</EM>:
<P></P>
<TD><CODE>im</CODE>
<P></P>
<TD>A single-banded <CODE>RenderedImage</CODE>.
<P></P>
<TR vAlign=top>
<TD><CODE>threshold</CODE>
<P></P>
<TD>The inclusion/exclusion threshold of the <CODE>ROI.</CODE>
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>Shape getAsShape()
<P></P></LI></UL></PRE>
<DL><A name=58926>
<DT>
<DD>returns a <CODE>Shape</CODE> representation of the <CODE>ROI</CODE>, if
possible. If none is available, null is returned. A proper instance of
<CODE>ROI</CODE> (one that is not an instance of any subclass of
<CODE>ROI</CODE>) will always return null. </A>
<P></P></DD></DL><PRE><UL>
<LI>PlanarImage getAsImage()
<P></P></LI></UL></PRE>
<DL><A name=58948>
<DT>
<DD>returns a <CODE>PlanarImage</CODE> representation of the
<CODE>ROI</CODE>. This method will always succeed. </A>
<P></P></DD></DL><PRE><UL>
<LI>int getThreshold()
<P></P></LI></UL></PRE>
<DL><A name=71152>
<DT>
<DD>returns the inclusion/exclusion threshold value. </A>
<P></P></DD></DL><PRE><UL>
<LI>void setThreshold(int threshold)
<P></P></LI></UL></PRE>
<DL><A name=71172>
<DT>
<DD>sets the inclusion/exclusion threshold value. </A>
<P></P></DD></DL><A name=71173>
<H4>6.2.1.1 <IMG src="Image Manipulation.files/space.gif">Determining the ROI
Bounds</H4></A>The <CODE>getBounds</CODE> methods in the <CODE>ROI</CODE>
class read the bounds of the <CODE>ROI</CODE>, as either a
<CODE>Rectangle</CODE> or a <CODE>Rectangle2D</CODE>.
<P>
<TABLE border=0>
<TBODY>
<TR>
<TD><IMG src="Image Manipulation.files/cistine.gif"></TD>
<TD>
<HR>
<B>API:</B> <CODE>javax.media.jai.ROI </CODE>
<HR>
</TD></TR></TBODY></TABLE><PRE><UL>
<LI>Rectangle getBounds()
<P></P></LI></UL></PRE>
<DL><A name=53917>
<DT>
<DD>returns the bounds of the <CODE>ROI</CODE> as a <CODE>Rectangle</CODE>.
</A>
<P></P></DD></DL><PRE><UL>
<LI>Rectangle2D getBounds2D()
<P></P></LI></UL></PRE>
<DL><A name=53921>
<DT>
<DD>returns the bounds of the <CODE>ROI</CODE> as a
<CODE>Rectangle2D</CODE>. </A>
<P></P></DD></DL><A name=54597>
<H4>6.2.1.2 <IMG src="Image Manipulation.files/space.gif">Determining if an
Area Lies Within or Intersects the ROI</H4></A>The <CODE>contains</CODE>
methods in the <CODE>ROI</CODE> class test whether a given point or
rectangular region lie within the <CODE>ROI</CODE>. The
<CODE>intersects</CODE> methods test whether a given rectangular region
intersect with the <CODE>ROI</CODE>.
<P>
<TABLE border=0>
<TBODY>
<TR>
<TD><IMG src="Image Manipulation.files/cistine.gif"></TD>
<TD>
<HR>
<B>API:</B> <CODE>javax.media.jai.ROI </CODE>
<HR>
</TD></TR></TBODY></TABLE><PRE><UL>
<LI>boolean contains(Point p)
<P></P></LI></UL></PRE>
<DL><A name=53997>
<DT>
<DD>returns true if the <CODE>Point</CODE> lies within the <CODE>ROI</CODE>.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD><EM>Parameters</EM>:
<P></P>
<TD><CODE>p</CODE>
<P></P>
<TD>A <CODE>Point</CODE> identifying the pixel to be queried.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>boolean contains(Point2D p)
<P></P></LI></UL></PRE>
<DL><A name=54025>
<DT>
<DD>returns true if the <CODE>Point2D</CODE> lies within the ROI.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD><EM>Parameters</EM>:
<P></P>
<TD><CODE>p</CODE>
<P></P>
<TD>A <CODE>Point2D</CODE> identifying the pixel to be queried.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>boolean contains(int x, int y)
<P></P></LI></UL></PRE>
<DL><A name=54038>
<DT>
<DD>returns true if the point lies within the ROI.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD rowSpan=2><EM>Parameters</EM>:
<P></P>
<TD><CODE>x</CODE>
<P></P>
<TD>An int specifying the <EM>x</EM> coordinate of the pixel to be
queried.
<P></P>
<TR vAlign=top>
<TD><CODE>y</CODE>
<P></P>
<TD>An int specifying the <EM>y</EM> coordinate of the pixel to be
queried.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>boolean contains(double x, double y)
<P></P></LI></UL></PRE>
<DL><A name=54057>
<DT>
<DD>returns true if the point lies within the ROI.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD rowSpan=2><EM>Parameters</EM>:
<P></P>
<TD><CODE>x</CODE>
<P></P>
<TD>A double specifying the <EM>x</EM> coordinate of the pixel to be
queried.
<P></P>
<TR vAlign=top>
<TD><CODE>y</CODE>
<P></P>
<TD>A double specifying the <EM>y</EM> coordinate of the pixel to be
queried.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>boolean contains(Rectangle rect)
<P></P></LI></UL></PRE>
<DL><A name=54067>
<DT>
<DD>returns true if the <CODE>Rectangle</CODE> lies within the ROI.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD><EM>Parameters</EM>:
<P></P>
<TD><CODE>rect</CODE>
<P></P>
<TD>A <CODE>Rectangle</CODE> specifying the region to be tested for
inclusion.
<P></P></TR></TBODY></TABLE></A>
<P></P></DD></DL><PRE><UL>
<LI>boolean contains(Rectangle2D r)
<P></P></LI></UL></PRE>
<DL><A name=53977>
<DT>
<DD>returns true if the <CODE>Rectangle2D</CODE> lies within the ROI.
<P>
<TABLE cellPadding=3 border=3>
<CAPTION><FONT size=-1><B></B></FONT></CAPTION>
<TBODY>
<TR vAlign=top>
<TD><EM>Parameters</EM>:
<P></P>
<TD><CODE>r</CODE>
<P></P>
<TD>A <CODE>Rectangle2D</CODE> specifying the region to be tested for
inclusion.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -