Package javax.media.jai

Examples of javax.media.jai.Histogram


    // Create the histogram
    //
    // /////////////////////////////////////////////////////////////////////
    final PlanarImage histogramImage = JAI.create("histogram", pb,
        new RenderingHints(JAI.KEY_TILE_CACHE, null));
    final Histogram hist = (Histogram) histogramImage
        .getProperty("histogram");
    pb.removeParameters();
    pb.removeSources();

    // /////////////////////////////////////////////////////////////////////
    //
    // Write things
    //
    // /////////////////////////////////////////////////////////////////////
    if (dest instanceof File) {
      // files destinations
      // write statistics
      if (dest instanceof File) {
        dest = new File((File) dest, new StringBuffer(name).append(
            ".STX").toString());
      }
      // writing world file
      final PrintWriter p = new PrintWriter(new FileOutputStream(
          ((File) dest)));
      p.print(1);
      p.print(" ");
      p.print((int) Min[0]);
      p.print(" ");
      p.print((int) Max[0]);
      p.print(" ");
      p.print(hist.getMean()[0]);
      p.print(" ");
      p.print(hist.getStandardDeviation()[0]);
      p.close();
    } else {
      final ZipOutputStream outZ = (ZipOutputStream) dest;
      final ZipEntry e = new ZipEntry(name + ".STX");
      outZ.putNextEntry(e);

      // writing world file
      outZ.write("1".getBytes());
      outZ.write(" ".getBytes());
      outZ.write(new Integer((int) Min[0]).toString().getBytes());
      outZ.write(" ".getBytes());
      outZ.write(new Integer((int) Max[0]).toString().getBytes());
      outZ.write(" ".getBytes());
      outZ.write(new Double(hist.getMean()[0]).toString().getBytes());
      outZ.write(" ".getBytes());
      outZ.write(new Double(hist.getStandardDeviation()[0]).toString()
          .getBytes());
      ((ZipOutputStream) dest).closeEntry();
    }

    histogramImage.dispose();
View Full Code Here


        // compute the histogram
        final RenderedOp hist = HistogramDescriptor.create(inputImage,
            null, Integer.valueOf(1), Integer.valueOf(1),
            new int[] { 256 }, new double[] { 0 },
            new double[] { 256 }, null);
        final Histogram h = (Histogram) hist.getProperty("histogram");

        // now compute the PDF and the CDF for the original image
        final byte[] cumulative = new byte[h.getNumBins(0)];

        // sum of bins (we might have excluded 0 hence we cannot really
        // optimise)
        float totalBinSum = 0;
        for (int i = 0; i < cumulative.length; i++) {
          totalBinSum += h.getBinSize(0, i);
        }

        // this is the scale factor for the histogram equalization
        // process
        final float scale = (float) (h.getHighValue(0) - 1 - h.getLowValue(0))/ totalBinSum;
        float sum = 0;
        for (int i = 1; i < cumulative.length; i++) {
          sum += h.getBinSize(0, i - 1);
          cumulative[i] = (byte) ((sum * scale + h.getLowValue(0)) + .5F);
        }

        final LookupTableJAI lookup = new LookupTableJAI(cumulative);
        final ParameterBlock pb = new ParameterBlock();
        pb.addSource(hist);
View Full Code Here

        ParameterValueGroup param = processor.getOperation("Histogram").getParameters();
        param.parameter("Source").setValue(source);

        GridCoverage2D processed = (GridCoverage2D) processor.doOperation(param);

        Histogram histo = (Histogram) processed.getProperty("histogram");
        assertNotNull(histo);

        assertEquals(256, histo.getNumBins()[0]);
    }
View Full Code Here

        param.parameter("Source").setValue(source);
        param.parameter("numBins").setValue(new int[]{10});
       
        GridCoverage2D processed = (GridCoverage2D) processor.doOperation(param);

        Histogram histo = (Histogram) processed.getProperty("histogram");
        assertNotNull(histo);

        assertEquals(10, histo.getNumBins()[0]);
    }
View Full Code Here

        param.parameter("numBins").setValue(new int[]{10});
        param.parameter("lowValue").setValue(new double[]{100});
        param.parameter("highValue").setValue(new double[]{200});
        GridCoverage2D processed = (GridCoverage2D) processor.doOperation(param);

        Histogram histo = (Histogram) processed.getProperty("histogram");
        assertNotNull(histo);

        assertEquals(10, histo.getNumBins()[0]);
        assertEquals(100d, histo.getBinLowValue(0, 0), 0d);
        assertEquals(200d, histo.getBinLowValue(0, 10), 0d);
    }
View Full Code Here

     * @param file
     * @return the deserialized histogram.
     */
    static Histogram getHistogram(final String file){
        Utilities.ensureNonNull("file", file);
        Histogram histogram = null;
       
        // Firstly: check if the histogram have been already
        // deserialized and it is available in cache
        if (ehcache != null && ehcache.isKeyInCache(file)){
            if (ehcache.isElementInMemory(file)){
View Full Code Here

                        //setup dynamic threshold
                        if (canonicalPath != null){
                            final String path = FilenameUtils.getFullPath(canonicalPath);
                            final String baseName = FilenameUtils.getBaseName(canonicalPath);
                            final String histogramPath = path + baseName + "." + "histogram";
                            final Histogram histogram = Utils.getHistogram(histogramPath);
                            if (histogram != null) {
                                final double[]p = histogram.getPTileThreshold(artifactsFilterPTileThreshold);
                                artifactThreshold = (int)p[0];
                            }
                        }
                    }
                    if (LOGGER.isLoggable(Level.FINE)){
View Full Code Here

      fis = new FileImageInputStream(file);
      reader = spi.createReaderInstance();
      reader.setInput(fis);
      RenderedImage image = reader.read(0);
      RenderedOp histogramOp = HistogramDescriptor.create(image, null, Integer.valueOf(1), Integer.valueOf(1), new int[]{256}, null, null, null);
      Histogram histogram = (Histogram) histogramOp.getProperty("histogram");
      int[][] bins = histogram.getBins();
   
      assertEquals(bins[0][0],4261);
      assertEquals(bins[1][0],4261);
      assertEquals(bins[2][0],4832);
      assertEquals(bins[0][20],127); // This bin will disappear in the Histogram of the filtered image
      assertEquals(bins[1][20],127); // This bin will disappear in the Histogram of the filtered image
      assertEquals(bins[2][20],127); // This bin will disappear in the Histogram of the filtered image
      assertEquals(bins[0][180],571);
      assertEquals(bins[0][200],5041);
      assertEquals(bins[2][200],5041);
      assertEquals(bins[1][255],5612);
     
      assertEquals(bins[0][0]+bins[1][0]+bins[2][0]+bins[0][20]+bins[1][20]+bins[2][20]+bins[0][180]+bins[0][200]+bins[2][200]+bins[1][255], 100*100*3);
     
      // Image filtering
      ROI roi = new ROIShape(new Rectangle(14, 11, 75, 75));
      double [] backgroundValues = new double[]{0.0d, 0.0d, 0.0d};
      RenderedImage filtered = ArtifactsFilterDescriptor.create(image, roi, backgroundValues, 30, 3, null);
      histogramOp = HistogramDescriptor.create(filtered, null, Integer.valueOf(1), Integer.valueOf(1), new int[]{256}, null, null, null);
      histogram = (Histogram) histogramOp.getProperty("histogram");
     
      bins = histogram.getBins();
     
      assertEquals(bins[0][0],4261);
      assertEquals(bins[1][0],4261);
      assertEquals(bins[2][0],4845);
      assertEquals(bins[0][180],584);
View Full Code Here

      imageChoice = new Integer(
          0);
    }

    final double[][] resolutionLevels = getResolutionLevels(coverageName);
    Histogram histogram = null;
    if (config.isEqualizeHistogram()) {
      histogram = getHistogram(
          coverageName,
          resolutionLevels[imageChoice.intValue()][0],
          resolutionLevels[imageChoice.intValue()][1]);
View Full Code Here

      pb.add(1);
      pb.add(new int[]{bins});
      pb.add(new double[]{0})
      pb.add(new double[]{256});
      PlanarImage dummy = JAI.create("histogram", pb);
      Histogram histogram = (Histogram) dummy.getProperty("histogram");
      dummy.setProperty("histogram", histogram.getBins());
     
    return ImageUtil.create(dummy);
  }
View Full Code Here

TOP

Related Classes of javax.media.jai.Histogram

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.