eHow launches Android app: Get the best of eHow on the go.

How To

How to Make a Histogram in Java

Contributor
By Ty Arthur
eHow Contributing Writer
(2 Ratings)
Make a Histogram in Java
Make a Histogram in Java
Sun Microsystems

A histogram is a graphical or numerical representation of the number of pixels and lines of color found in an image. Some high-end digital cameras will display this information for you in their settings, but to get the histograms of images you have on your computer, you will need to code a simple Java program.

Difficulty: Moderate
Instructions

Things You'll Need:

  • Java Advanced Imaging API
  1. Step 1

    Open the Java program and start a new project.

  2. Step 2

    Use the "PlanarImage" and "Create" functions to load an image on your hard drive into the new program's memory. Write out the code so the first line of the program reads something like "PlanarImage picturename JAI.create("fileload",picturename.Getabsolutepath())"

  3. Step 3

    Make a new array using double integers ranging from zero to 256. Define both the low end of the array and the high end of the array using brackets and a semicolon, just as you would when making any other array.

  4. Step 4

    Add the image into the array, then count through the lines of color in the image using the ".add" command.

  5. Step 5

    Use the "GetProperty" feature to produce a Histogram of the image. The code should read "op.Getproperty("histogram")"

  6. Step 6

    Execute the program to finish making the histogram.

Tips & Warnings
  • You can display the histogram information in an easy-to-read chart by passing the information in the array as a string by using the "GraphIt" feature of the "Chart" function.

Comments  

sergei175 said

Flag This Comment

on 11/1/2009
You can use the jHepWork Java libraries,
see http://jwork.org/jhepwork/

The classes are H1D, H2D, H3D.
This is an example:

import java.awt.Color;
import java.util.Random;
import jhplot.*;

class histo1
{

public static void main(String[] args)
{


HPlot c1 = new HPlot("Canvas",600,400,1,1);
c1.setGTitle("Global title for F_{2} and x_{γ} ");
c1.visible(true);
c1.setAutoRange();


H1D h1 = new H1D("Simple1",20, -2.0, 2.0);
Random rand = new Random();
for (int i=0; i<100; i++) h1.fill(rand.nextGaussian());


c1.draw(h1);
h1.setColor(Color.blue);
h1.setPenWidthErr(2);
c1.setNameX("Xaxis");
c1.setNameY("Yaxis");
c1.setName("Canvas title");
c1.drawStatBox(h1);
c1.update();

// make png figure
c1.export("test.png");

}


}
~

Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics