⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image acquisition and display.htm

📁 是一部关于java高级图像处理的的一本入门书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0096)http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html -->
<HTML><HEAD><TITLE>Image Acquisition and Display</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 Acquisition and Display.files/contents.gif"></A> <A 
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Programming-environ.doc.html"><IMG 
alt=Previous src="Image Acquisition and Display.files/previous.gif"></A> <A 
href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Color.doc.html"><IMG 
alt=Next src="Image Acquisition and Display.files/next.gif"></A> 
<P><FONT size=5><I>Programming in Java Advanced Imaging</I></FONT> </CENTER><BR>
<CENTER><A name=81548>
<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 Acquisition and Display.files/sm-space.gif">4</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<CENTER><A name=81550>
<TABLE width="90%" border=0>
  <TBODY>
  <TR>
    <TD align=right>
      <HR noShade SIZE=7>
      <FONT size=6>Image Acquisition and 
Display</FONT></TD></TR></TBODY></TABLE></A></CENTER>
<BLOCKQUOTE>
  <P><BR><BR><BR>
  <P><FONT size=7><B>T</B></FONT>HIS chapter describes the Java Advanced Imaging 
  (JAI) API image data types and the API constructors and methods for image 
  acquisition and display. 
  <P><A name=50856>
  <H2>4.1 <IMG 
  src="Image Acquisition and Display.files/space.gif">Introduction</H2></A>All 
  imaging applications must perform the basic tasks of acquiring, displaying, 
  and creating (recording) images. Images may be acquired from many sources, 
  including a disk file, the network, a CD, and so on. Images may be acquired, 
  processed, and immediately displayed, or written to a disk file for display at 
  a later time. 
  <P>As described in <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Programming-environ.doc.html#47227">Chapter 
  3</A>, JAI offers the programmer the flexibility to render and display an 
  image immediately or to defer the display of the rendered image until there is 
  a specific request for it. 
  <P>Image acquisition and display are relatively easy in JAI, in spite of all 
  the high-level information presented in the next several sections. Take for 
  example, the sample code in <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#82325">Listing 
  4-1</A>. This is a complete code example for a simple application called 
  <CODE>FileTest</CODE>, which takes a single argument; the path and name of the 
  file to read. <CODE>FileTest</CODE> reads the named file and displays it in a 
  <CODE>ScrollingImagePanel</CODE>. The operator that reads the image file, 
  <CODE>FileLoad</CODE>, is described in <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#69930">Section 
  4.4.1.2, "The FileLoad Operation</A>." The <CODE>ScrollingImagePanel</CODE> is 
  described in <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#73265">Section 
  4.8, "Image Display</A>."
  <P><CAPTION><FONT size=-1><B><A name=82325>
  <CENTER><FONT size=-1><B><I>Listing 4-1 </I><IMG 
  src="Image Acquisition and Display.files/sm-blank.gif" border=0> Example 
  Program to Read and Display an Image File </B></FONT></CENTER></A>
  <P></B></FONT></CAPTION>
  <HR>
  <TR valign="top"><TD rowspan="7" colspan="1"><PRE>     // Specify the classes to import.
     import java.awt.image.renderable.ParameterBlock;
     import java.io.File;
     import javax.media.jai.JAI;
     import javax.media.jai.PlanarImage;
     import javax.media.jai.RenderedOp;
     import javax.media.jai.widget.ScrollingImagePanel;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TD><PRE>     public class FileTest extends WindowContainer {
</PRE><TR valign="top"><TD><PRE>     // Specify a default image in case the user fails to specify
     // one at run time.
     public static final String DEFAULT_FILE = 
                                    "./images/earth.jpg";
</PRE><TR valign="top"><TD rowspan="3" colspan="1"><PRE>         public static void main(String args[]) {
             String fileName = null;
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="11" 
  colspan="1"><PRE>     // Check for a filename in the argument.
             if(args.length == 0) {
                 fileName = DEFAULT_FILE;
             } else if(args.length == 1) {
                 fileName = args[0];
             } else {
                 System.out.println("\nUsage: java " +
                                    (new FileTest()).getClass().getName() +
                                    " [file]\n");
                 System.exit(0);
             }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top"><TD rowspan="3" colspan="1"><PRE>             new FileTest(fileName);
         }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="2" 
  colspan="1"><PRE>         public FileTest() {}
         public FileTest(String fileName) {
</PRE><TR valign="top"><TR valign="top"><TD rowspan="6" colspan="1"><PRE>        // Read the image from the designated path.
        System.out.println("Creating operation to load image from '" +
                            fileName+"'");
        RenderedOp img =  JAI.create("fileload", fileName);
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TD rowspan="3" colspan="1"><PRE>        // Set display name and layout.
        setTitle(getClass().getName()+": "+fileName);
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TD rowspan="8" 
  colspan="1"><PRE>             // Display the image.
             System.out.println("Displaying image");
             add(new ScrollingImagePanel(img, img.getWidth(),
                                         img.getHeight()));
             pack();
             show();
         }
     }
</PRE><TR valign="top"><TR valign="top"><TR valign="top"><TR valign="top"><TR 
  valign="top"><TR valign="top"><TR valign="top">
  <HR>

  <P>
  <P><A name=51157>
  <H3>4.1.1 <IMG src="Image Acquisition and Display.files/space.gif">Image 
  Data</H3></A>Image data is, conceptually, a three-dimensional array of pixels, 
  as shown in <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#51833">Figure 
  4-1</A>. Each of the three arrays in the example is called a <EM>band</EM>. 
  The number of rows specifies the image height of a band, and the number of 
  columns specifies the image width of a band. 
  <P>Monochrome images, such as a grayscale image, have only one band. Color 
  images have three or more bands, although a band does not necessarily have to 
  represent color. For example, satellite images of the earth may be acquired in 
  several different spectral bands, such as red, green, blue, and infrared. 
  <P>In a color image, each band stores the red, green, and blue (RGB) 
  components of an additive image, or the cyan, magenta, and yellow (CMY) 
  components of a three-color subtractive image, or the cyan, magenta, yellow, 
  and black (CMYK) components of a four-color subtractive image. Each pixel of 
  an image is composed of a set of <EM>samples</EM>. For an RGB pixel, there are 
  three samples; one each for red, green, and blue. 
  <P>An image is sampled into a rectangular array of pixels. Each pixel has an 
  (<EM>x</EM>,<EM>y</EM>) coordinate that corresponds to its location within the 
  image. The <EM>x</EM> coordinate is the pixel's horizontal location; the 
  <EM>y</EM> coordinate is the pixel's vertical location. Within JAI, the pixel 
  at location (0,0) is in the upper left corner of the image, with the 
  <EM>x</EM> coordinates increasing in value to the right and <EM>y</EM> 
  coordinates increasing in value downward. Sometimes the <EM>x</EM> coordinate 
  is referred to as the pixel number and the <EM>y</EM> coordinate as the line 
  number. 
  <P><A name=51832>
  <HR>

  <CENTER><IMG 
  src="Image Acquisition and Display.files/Acquisition.doc.anc1.gif"></CENTER>
  <HR>
  </A><A name=51833>
  <CENTER><FONT size=-1><B><I>Figure 4-1 </I><IMG 
  src="Image Acquisition and Display.files/sm-blank.gif" border=0> Multi-band 
  Image Structure</B></FONT></CENTER></A>
  <P><A name=52258>
  <H3>4.1.2 <IMG src="Image Acquisition and Display.files/space.gif">Basic 
  Storage Types</H3></A>In the JAI API, the basic unit of data storage is the 
  <CODE>DataBuffer</CODE> object. The <CODE>DataBuffer</CODE> object is a kind 
  of raw storage that holds all the samples that make up the image, but does not 
  contain any information on how those samples are put together as pixels. How 
  the samples are put together is contained in a <CODE>SampleModel</CODE> 
  object. The <CODE>SampleModel</CODE> class contains methods for deriving pixel 
  data from a <CODE>DataBuffer</CODE>. 
  <P>JAI supports several image data types, so the <CODE>DataBuffer</CODE> class 
  has the following subclasses, each representing a different data type: 
  <P>
  <UL>
    <LI><CODE>DataBufferByte</CODE> - stores data internally as bytes (8-bit 
    values)
    <P></P></LI></UL>
  <UL>
    <LI><CODE>DataBufferShort</CODE> - stores data internally as shorts (16-bit 
    values)
    <P></P></LI></UL>
  <UL>
    <LI><CODE>DataBufferUShort</CODE> - stores data internally as unsigned 
    shorts (16-bit values)<CODE></CODE>
    <P></P></LI></UL>
  <UL>
    <LI><CODE>DataBufferInt</CODE> - stores data internally as integers (32-bit 
    values)
    <P></P></LI></UL>
  <UL>
    <LI><CODE>DataBufferFloat</CODE> - stores data internally as 
    single-precision floating-point values.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>DataBufferDouble</CODE> - stores data internally as 
    double-precision floating-point values.
    <P></P></LI></UL><A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Acquisition.doc.html#78780">Table 
  4-1</A> lists the <CODE>DataBuffer</CODE> type elements.
  <P>
  <TABLE cellPadding=3 border=3>
    <CAPTION><FONT size=-1><B><A name=78780><I>Table 4-1 </I><IMG 
    src="Image Acquisition and Display.files/sm-blank.gif" border=0> Data Buffer 
    Type Elements </A></B></FONT></CAPTION>
    <TBODY>
    <TR vAlign=top>
      <TH><A name=78784>Name </A>
      <TH><A name=78786>Description </A>
    <TR vAlign=top>
      <TD><A name=78859>TYPE_INT</A><BR>
      <TD><A name=78861>Tag for int data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78788>TYPE_BYTE</A><BR>
      <TD><A name=78790>Tag for unsigned byte data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78867>TYPE_SHORT</A><BR>
      <TD><A name=78869>Tag for signed short data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78871>TYPE_USHORT</A><BR>
      <TD><A name=78873>Tag for unsigned short data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78792>TYPE_DOUBLE</A><BR>
      <TD><A name=78794>Tag for double data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78796>TYPE_FLOAT</A><BR>
      <TD><A name=78798>Tag for float data.</A><BR>
    <TR vAlign=top>
      <TD><A name=78851>TYPE_UNDEFINED</A><BR>
      <TD><A name=78853>Tag for undefined data.</A><BR></TR></TBODY></TABLE>
  <P>
  <P>JAI also supports a large number of image data formats, so the 
  <CODE>SampleModel</CODE> class provides the following types of sample models: 
  <P>
  <UL>
    <LI><CODE>ComponentSampleModel</CODE> - used to extract pixels from images 
    that store sample data in separate data array elements in one bank of a 
    <CODE>DataBuffer</CODE> object.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>ComponentSampleModelJAI</CODE> - used to extract pixels from 
    images that store sample data such that each sample of a pixel occupies one 
    data element of the <CODE>DataBuffer</CODE>.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>BandedSampleModel</CODE> - used to extract pixels from images that 
    store each sample in a separate data element with bands stored in a sequence 
    of data elements.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>PixelInterleavedSampleModel</CODE> - used to extract pixels from 
    images that store each sample in a separate data element with pixels stored 
    in a sequence of data elements.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>MultiPixelPackedSampleModel</CODE> - used to extract pixels from 
    single-banded images that store multiple one-sample pixels in one data 
    element.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>SinglePixelPackedSampleModel</CODE> - used to extract samples from 
    images that store sample data for a single pixel in one data array element 
    in the first bank of a <CODE>DataBuffer</CODE> object.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>FloatComponentSampleModel</CODE> - stores <EM>n</EM> samples that 
    make up a pixel in <EM>n</EM> separate data array elements, all of which are 
    in the same bank in a <CODE>DataBuffer</CODE> object. This class supports 
    different kinds of interleaving.
    <P></P></LI></UL>The combination of a <CODE>DataBuffer</CODE> object, a 
  <CODE>SampleModel</CODE> object, and an origin constitute a meaningful 
  multi-pixel image storage unit called a <CODE>Raster</CODE>. The 
  <CODE>Raster</CODE> class has methods that directly return pixel data for the 
  image data it contains. 
  <P>There are two basic <CODE>Raster</CODE> types: 
  <P>
  <UL>
    <LI><CODE>Raster</CODE> - represents a rectangular array of pixels. This is 
    a "read-only" class that only has get methods.
    <P></P></LI></UL>
  <UL>
    <LI><CODE>WritableRaster</CODE> - extends <CODE>Raster</CODE> to provide 
    pixel writing capabilities.
    <P></P></LI></UL>There are separate interfaces for dealing with each raster 
  type: 
  <P>
  <UL>
    <LI>The <CODE>RenderedImage</CODE> interface assumes the data is read-only 
    and, therefore, does not contain methods for writing a <CODE>Raster</CODE>.
    <P></P></LI></UL>
  <UL>
    <LI>The <CODE>WriteableRenderedImage</CODE> interfaces assumes that the 
    image data can be modified.
    <P></P></LI></UL>A <CODE>ColorModel</CODE> class provides a color 
  interpretation of pixel data provided by the image's sample model. The 
  abstract <CODE>ColorModel</CODE> class defines methods for turning an image's 
  pixel data into a color value in its associated <CODE>ColorSpace</CODE>. See 
  <A 
  href="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Color.doc.html#51226">Section 
  5.2.1, "Color Models</A>." 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -