advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Using Rasters for Image Processing, Part 1 :

Methods for Extracting and Setting Samples in a DataBuffer

There are two categories of methods that can be used for extracting samples from a data buffer. The first category contains the getSampleXXX methods. To extract the samples from a data buffer as integer values, use the following methods:
  • public int getSample(int x, int y, int band, DataBuffer DB): This method returns an int representing the sample from the specified band belonging to a pixel with the (x,y) coordinates. You also specify the data buffer:
    
    int sample=SM.getSample(20,35,2,DB);
    System.out.println("Sample value:"+sample);
    
  • public int[] getSamples(int x,int y, int w, int h, int band, int[] res, DataBuffer DB): This method returns an array of integers representing all the samples in the rectangular area (x,y,w,h). Select the band and the data buffer by supplying the arguments band and DB. The samples are stored in the res array, one sample per element:
    
    int[] res=new int[W*H]; 
    res=SM.getSamples(0,0,W,H,0,res,DF);
    for(int i=0;i<res.length;i++)
       System.out.println("res["+i+"]="+res[i]);
    
If you want to extract the samples from a data buffer as float values, use these two methods:
  • public float getSampleFloat(int x, int y, int band, DataBuffer DB)
  • public float[] getSamples(int x,int y, int w, int h, int band, float[] res, DataBuffer DB)
If you want to extract the samples from a data buffer as double values, use these two methods:
  • public double getSampleDouble(int x, int y, int band, DataBuffer DB)
  • public double[] getSamples(int x,int y, int w, int h, int band, double[] res, DataBuffer DB)
To understand the above four methods, try making an analogy with the methods from this category used to extract the samples from a data buffer as integer values.

The second category contains the getPixelXXX methods. To extract the samples from a data buffer as integer values, use the following methods:

  • public int[] getPixel(int x, int y, int[] res, DataBuffer DB): This method returns all the samples of the pixel that have the (x,y) coordinates in the integer res array. The DB argument represents the data buffer.
    
    int[] res=new int[SM.getNumBands()];
    res=SM.getPixel(45,35,res,DF);
    for(int i=0;i<res.length;i++)
         System.out.println("res["+i+"]="+res[i]);
    
  • public int[] getPixels(int x, int y, int l, int h, int[] res, DataBuffer DB): This method returns an array of integers representing all the samples of the pixels found in the rectangular area (x,y,w,h). Every res element stores one sample. The DB argument represents the data buffer.
    
    int[] res=new int[W*H*SM.getNumBands()];
    res=SM.getPixels(0,0,W,H,res,DF);
    for(int i=0;i<res.length;i++)
          System.out.println("res["+i+"]="+res[i]);
    
To return the samples in a float array, use the following two methods:
  • public float[] getPixel(int x, int y, float[] res, DataBuffer DB)
  • public float[] getPixels(int x, int y, int w, int h, float[] res, DataBuffer DB)
To return the samples in a float array, use the following two methods:
  • public double[] getPixel(int x, int y, double[] res, DataBuffer DB)
  • public double[] getPixels(int x, int y, int w, int h, double[] res, DataBuffer DB)
To understand the above four methods, try making an analogy with the methods from this category used to extract the samples from a data buffer as integer values.

To set the samples in a DataBuffer, use the group of set methods. These methods are similar to the get methods for extracting samples from a DataBuffer.

Home / Articles / Using Rasters for Image Processing, Part 1 / 1 / 2 / 3 / 4 / Next Page

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 38
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel
Jim Zemlin: The New Center of Linux Gravity
Microsoft's Novell Investment Tops $340M
Fedora 10 Takes Shape
IBM Gives a Mobile Voice to Developers
Inadequate Tools Send Software Down the Drain
USB 3.0 One Step Closer to Reality
Would-Be Linux Contributors May Get a Leg Up

State of the Semantic Web: Know Where to Look
A 3D Exploration of the HTML Canvas Element
Setting Up and Running Subversion and Tortoise SVN with Visual Studio and .NET
Java/JRuby Developers, Say Open 'Sesame' to the Semantic Web
Interpreting Images with MRDS Services
DevXtra Editors' Blog: Executives Avoiding Cloud Computing in Droves
Q&A with James Reinders on the Intel Parallel Studio Beta Program
The Pros and Cons of Outsourcing Enterprise Emails
Hosting Options: Shared or Dedicated Server
Movin' On Up: How to Hop to a New Host

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers