Building a Histogram in JAI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oracle3001

    Building a Histogram in JAI

    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(s ource);
    pb2.add(histogr am);
    pb2.add(null);
    pb2.add(1);
    pb2.add(1);

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

    // get histogram contents
    int[] local_array = new int[histogram.getNu mBins(0)];
    for ( int i = 0; i < histogram.getNu mBins(0); i++ ) {
    local_array = histogram.getBi nSize(0, i);
    System.out.prin tln("No Of Bins:- "+local_arr ay) ;
    }



    ParameterBlock pb = new ParameterBlock( );

    low[0] = 0.0F;
    high[0] = 106.0F;
    pb.addSource(so urce);
    pb.add(low);
    pb.add(high);
    pb.add(map);
    target = JAI.create("thr eshold", pb, null);
    display.set(tar get);

    return target ;

    }

    Exception in thread "main" java.lang.Illeg alArgumentExcep tion: Histogram -
    Param
    eter value`s class (javax.media.ja i.Histogram) is not an instance of the
    paramet
    er class (javax.media.ja i.ROI) for parameter "roi".
    at javax.media.jai .JAI.createNS(J AI.java:1091)
    at javax.media.jai .JAI.create(JAI .java:977)
    at Threshold.thres holding(Thresho ld.java:116)
    at Main.<init>(Mai n.java:66)
    at Test.main(Test. java:6)

    Adam



Working...