I m making App in java using Swing component and JAI library. I make histogram of black and white or gray scale image.Is this method of making histogram correct? iif it is correct then how can i do normalization and Equalization of histogram in my App in java using JAI library?my code is below. in my code i make BufferedImage object and then make and plot histogram of that image .
enter code here
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.*;
public class FinalHistogram extends JPanel {
static int[] bins = new int[256];
static int[] newBins = new int[256];
static int x1 = 0, y1 = 0;
static PlanarImage image = JAI.create("fileload", "alp_finger.tiff");
static BufferedImage bi = image.getAsBufferedImage();
FinalHistogram(int[] pbins) {
for (int i = 0; i < 256; i++) {
bins[i] = pbins[i];
newBins[i] = 0;
}
repaint();
}
@Override
protected void paintComponent(Graphics g) {
for (int i = 0; i < 256; i++) {
g.drawLine(150 + i, 300, 150 + i, 300 - (bins[i] / 300));
if (i == 0 || i == 255) {
String sr = new Integer((i)).toString();
g.drawString(sr, 150 + i, 305);
}
System.out.println("bin[" + i + "]===" + bins[i]);
}
}
public static void main(String[] args) throws IOException {
int[] sbins = new int[256];
int pixel = 0;
int k = 0;
for (int x = 0; x < bi.getWidth(); x++) {
for (int y = 0; y < bi.getHeight(); y++) {
pixel = bi.getRaster().getSample(x, y, 0);
k = (int) (pixel / 256);
sbins[k]++;
//pixel = bi.getRGB(x, y) & 0x000000ff;
//k=pixel;
//int[] pixels = m_image.getRGB(0, 0, m_image.getWidth(), m_image.getHeight(), null, 0, m_image.getWidth());
//short currentValue = 0;
//int red,green,blue;
//for(int i = 0; i<pixels.length; i++){
//red = (pixels[i] >> 16) & 0x000000FF;
//green = (pixels[i] >>8 ) & 0x000000FF;
//blue = pixels[i] & 0x000000FF;
//currentValue = (short)((red + green + blue) / 3); //Current value gives the average //Disregard the alpha
//assert(currentValue >= 0 && currentValue <= 255); //Something is awfully wrong if this goes off...
//m_histogramArray[currentValue] += 1; //Increment the specific value of the array
//}
}
}
JTabbedPane jtp = new JTabbedPane();
jtp.addTab("Histogram", new JScrollPane(new FinalHistogram(sbins)));
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.add(new JScrollPane(jtp));
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}