Example usage for java.awt.image RenderedImage getData

List of usage examples for java.awt.image RenderedImage getData

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getData.

Prototype

Raster getData(Rectangle rect);

Source Link

Document

Computes and returns an arbitrary region of the RenderedImage.

Usage

From source file:org.geopublishing.atlasStyler.classification.RasterClassification.java

/**
 * This is where the magic happens. Here the attributes of the features are
 * summarized in a {@link DynamicBin1D} class.
 * //from w w  w. j  ava 2  s  .c o m
 * @throws IOException
 */
@Override
synchronized public DynamicBin1D getStatistics() throws InterruptedException, IOException {

    cancelCalculation.set(false);

    if (stats == null) {
        GridCoverage2D coverage = getStyledRaster().getGeoObject().read(null);

        stats = new DynamicBin1D();

        noDataValuesCount.set(0);

        final RenderedImage rim = coverage.getRenderedImage();

        long size = Long.valueOf(rim.getHeight()) * Long.valueOf(rim.getWidth());
        long maxPixels = 3000000l;
        if (size > maxPixels) {
            setSubsampling((int) (size / maxPixels));
            LOGGER.info("Subsampling to every " + getSubsampling() + " pixel");
        }

        for (int row = 0; row < rim.getHeight(); row++) {

            if (row % getSubsampling() != 0) {
                // Skipping this line for Subsampling
                continue;
            } else {
                // DO
                //               System.out.println("");
            }

            int x1 = 0;
            int w = rim.getWidth();

            int y1 = row;
            int h = 1;

            Raster data = rim.getData(new Rectangle(x1, y1, w, h));
            double[] values = data.getSamples(0, y1, w, h, getBand(), (double[]) null);

            final DoubleArrayList doubleArrayList = new DoubleArrayList(values);

            if (getStyledRaster().getNodataValue() != null) {
                int sizewithNodata = doubleArrayList.size();
                doubleArrayList
                        .removeAll(new DoubleArrayList(new double[] { getStyledRaster().getNodataValue() }));
                noDataValuesCount.addAndGet(sizewithNodata - doubleArrayList.size());
            }

            stats.addAllOf(doubleArrayList);

            //            LOGGER.debug("Added "+doubleArrayList.size()+" to statistics");
            //            LOGGER.debug(stats.size()+" in stats");
            doubleArrayList.clear();
        }

    }
    return stats;
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

private RenderedImage removeFactorsApplied(final RenderedImage downSampledImage,
        final Rectangle sourceTileRectangle) {

    final int sx0 = sourceTileRectangle.x;
    final int w = downSampledImage.getWidth();
    final int h = downSampledImage.getHeight();
    final double[] array = new double[h * w];
    //final Raster data = downSampledImage.getData();
    final Raster data = downSampledImage.getData(new Rectangle(0, 0, w, h));
    double sigma;
    int k = 0;/*from w w w .  j  a  v a 2s  .c  o m*/
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

            sigma = data.getSampleDouble(x, y, 0);

            if (antennaPatternCorrectionFlag) {
                sigma *= antennaPatternGain[sx0 + x * blockWidth];
            }

            if (rangeSpreadingLossCompFlag) {
                sigma /= rangeSpreadingLoss[sx0 + x * blockWidth];
            }

            if (!isERS1Mission) {
                sigma /= replicaPulseVariationsCorrectionFactor;
            }

            array[k++] = Math.sqrt(sigma);
        }
    }

    return createRenderedImage(array, w, h);
}