Building a Histogram using JAI

O

Oracle3001

Hi All, I am trying to use JAI to build a histogram of an image i have. I
have posted the code below, and the error I get at runtime. I have taken the
code from the offical java examples, so I am really puzzled why it doesn't
work

public PlanarImage thresholding (PlanarImage source) {

// set up the histogram
int[] bins = { 256 };
double[] low = { 0.0D };
double[] high = { 256.0D };

Histogram histogram = new Histogram(bins, low, high);

ParameterBlock pb2 = new ParameterBlock();
pb2.addSource(source);
pb2.add(histogram);
pb2.add(null);
pb2.add(1);
pb2.add(1);

RenderedOp op = JAI.create("histogram", pb2, null);
histogram = (Histogram) op.getProperty("histogram");

// get histogram contents
int[] local_array = new int[histogram.getNumBins(0)];
for ( int i = 0; i < histogram.getNumBins(0); i++ ) {
local_array = histogram.getBinSize(0, i);
System.out.println("No Of Bins:- "+local_array) ;
}



ParameterBlock pb = new ParameterBlock();

low[0] = 0.0F;
high[0] = 106.0F;
pb.addSource(source);
pb.add(low);
pb.add(high);
pb.add(map);
target = JAI.create("threshold", pb, null);
display.set(target);

return target ;

}

Exception in thread "main" java.lang.IllegalArgumentException: Histogram -
Param
eter value`s class (javax.media.jai.Histogram) is not an instance of the
paramet
er class (javax.media.jai.ROI) for parameter "roi".
at javax.media.jai.JAI.createNS(JAI.java:1091)
at javax.media.jai.JAI.create(JAI.java:977)
at Threshold.thresholding(Threshold.java:116)
at Main.<init>(Main.java:66)
at Test.main(Test.java:6)

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top