Hi all,

I need to generate a histogram for an image and have done so as shown below. However, I am not sure on how to view the histogram. If someone cld tell me how to go abt to edit the code such that I cld be able to view the histogram would be great. I have attached the code below. Any help would be greatly appreciated!


import java.lang.String;
import javax.media.jai.Histogram;
import javax.media.jai.PlanarImage;
import javax.media.jai.JAI;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.RenderedOp;

public class his {
public static PlanarImage getHistogram (PlanarImage image) {
/* set up the histogram */
int[] bins = { 256 };
double[] low = { 0.0D };
double[] high = { 256.0D };
/* Create one histogram with 256 bins. */
ParameterBlock pb1 = new ParameterBlock();
pb1.addSource(image);
pb1.add(null); // The ROI
pb1.add(1);
pb1.add(1); // Sampling
pb1.add(bins); // Bins
pb1.add(low);
pb1.add(high); // Range for inclusion
/* Gets the histogram */
PlanarImage imageTemp = JAI.create("histogram", pb1);
Histogram histogram = (javax.media.jai.Histogram)imageTemp.getProperty(" histogram");
/* get histogram contents */
int[] local_array = new int[histogram.getNumBins(0)];
for ( int i = 0; i < histogram.getNumBins(0); i++ ) {
local_array[i] = histogram.getBinSize(0, i);
}
return imageTemp;
}


public static void main(String args[])
{PlanarImage image = JAI.create("fileload", "C:/pic/pic2.jpg");
image=getHistogram(image);

// Write(image,"C:/pic/test_his.jpg");
}
}

Thanks :)