Example usage for java.awt.image Raster getSampleDouble

List of usage examples for java.awt.image Raster getSampleDouble

Introduction

In this page you can find the example usage for java.awt.image Raster getSampleDouble.

Prototype

public double getSampleDouble(int x, int y, int b) 

Source Link

Document

Returns the sample in a specified band for a pixel located at (x,y) as a double.

Usage

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.  ja  va2  s  .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);
}

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

private double[][] computeADCPowerLossValue(final RenderedImage squaredImage,
        final TileDescriptionFlags tileDescriptionFlags) {

    final int delH = (windowHeight / 2) / blockHeight;
    final int delW = (windowWidth / 2) / blockWidth;

    int x0 = 0;/*from ww  w.  j  a  v a  2s . c  o  m*/
    int y0 = 0;
    int w = squaredImage.getWidth();
    int h = squaredImage.getHeight();
    if (tileDescriptionFlags.adcSourceTileTopExtFlag) {
        y0 = delH;
        h -= delH;
    }
    if (tileDescriptionFlags.adcSourceTileBottomExtFlag) {
        h -= delH;
    }
    if (h <= 0)
        h = 1;

    if (tileDescriptionFlags.adcSourceTileLeftExtFlag) {
        x0 = delW;
        w -= delW;
    }
    if (tileDescriptionFlags.adcSourceTileRightExtFlag) {
        w -= delW;
    }
    if (w <= 0)
        w = 1;

    double[][] adcPowerLoss = new double[h][w];

    Raster data = squaredImage.getData();

    double dn;
    for (int y = y0; y < y0 + h; y++) {
        for (int x = x0; x < x0 + w; x++) {
            dn = data.getSampleDouble(x, y, 0);
            if (isERS1Mission) {
                adcPowerLoss[y - y0][x - x0] = getPowerLossValue(dn, appendixF1);
            } else {
                adcPowerLoss[y - y0][x - x0] = getPowerLossValue(dn, appendixF2);
            }
        }
    }
    /*
    for (int x = 0; x < w; x++) {
    System.out.print(adcPowerLoss[25][x] + ",");
    }
    System.out.println();
    */
    return adcPowerLoss;
}

From source file:org.esa.nest.gpf.oceantools.WindFieldEstimationOp.java

private static double getPeakSpectrumValue(final RenderedImage filteredImage, final double[][] array,
        final int n3) {

    final Raster data = filteredImage.getData();
    double peakValue = 0.0;
    final int length = 2 * n3 + 1;
    for (int y = 0; y < length; y++) {
        for (int x = 0; x < length; x++) {
            array[y][x] = data.getSampleDouble(x, y, 0);
            if (peakValue < array[y][x]) {
                peakValue = array[y][x];
            }/*from   w ww  .  j  a  va2 s  .c o  m*/
        }
    }
    return peakValue;
}

From source file:org.kalypso.grid.TiffGeoGrid.java

@Override
public double getValue(final int x, final int y) {
    if (m_image == null)
        return Double.NaN;

    final int tileX = m_image.XToTileX(x);
    final int tileY = m_image.YToTileY(y);

    final Raster tile = m_image.getTile(tileX, tileY);

    return tile.getSampleDouble(x, y, 0);
}

From source file:org.mrgeo.image.ImageStats.java

/**
 * Computes pixel value statistics: min, max, sum, count, & mean for a Raster and returns an array
 * of ImageStats objects, one for each band in the image.
 * //from   w  w w  .ja va 2s .  co m
 * @param raster
 *          the raster to compute stats for
 * @param nodata
 *          the value to ignore
 * @return an array of ImageStats objects
 */
static public void computeAndUpdateStats(final ImageStats[] tileStats, final Raster raster,
        final double[] nodata) throws RasterWritableException {
    final int type = raster.getTransferType();
    Number sample;
    for (int y = 0; y < raster.getHeight(); y++) {
        for (int x = 0; x < raster.getWidth(); x++) {
            for (int b = 0; b < raster.getNumBands(); b++) {
                switch (type) {
                case DataBuffer.TYPE_BYTE:
                case DataBuffer.TYPE_INT:
                case DataBuffer.TYPE_SHORT:
                case DataBuffer.TYPE_USHORT:
                    sample = raster.getSample(x, y, b);
                    break;
                case DataBuffer.TYPE_FLOAT:
                    sample = raster.getSampleFloat(x, y, b);
                    break;
                case DataBuffer.TYPE_DOUBLE:
                    sample = raster.getSampleDouble(x, y, b);
                    break;
                default:
                    throw new RasterWritableException(
                            "Error computing tile statistics. Unsupported raster data type");
                }
                updateStats(tileStats[b], sample, nodata[b]);
            }
        }
    }

}

From source file:org.mrgeo.image.ImageStats.java

/**
 * Deserialize a Raster into an array of ImageStats objects. Used to reduce tile stats emitted by
 * a mapper.//from  w  w  w. j  av  a2s  . c om
 * 
 * @param raster
 *          the raster containing stats measures as pixel values
 * @return an array of ImageStats objects
 */
static public ImageStats[] rasterToStats(final Raster raster) {
    final int bands = raster.getHeight();
    final ImageStats[] stats = initializeStatsArray(bands);
    for (int i = 0; i < bands; i++) {
        stats[i].min = raster.getSampleDouble(0, i, 0);
        stats[i].max = raster.getSampleDouble(1, i, 0);
        stats[i].sum = raster.getSampleDouble(2, i, 0);
        stats[i].count = raster.getSample(3, i, 0);
    }
    return stats;
}

From source file:org.mrgeo.image.ImageStats.java

public void calculateStats(final Raster r) {
    count = 0;/*from   w  w  w  .j  av a 2 s  .c  om*/
    sum = 0;
    for (int py = r.getMinY(); py < r.getMinY() + r.getHeight(); py++) {
        for (int px = r.getMinX(); px < r.getMinX() + r.getWidth(); px++) {
            final double v = r.getSampleDouble(px, py, 0);
            min = Math.min(min, v);
            max = Math.max(max, v);
            if (!Double.isNaN(v)) {
                sum += v;
                count++;
            }
        }
    }
    mean = sum / count;
}