Example usage for java.awt.image Raster getMinY

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

Introduction

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

Prototype

public final int getMinY() 

Source Link

Document

Returns the minimum valid Y coordinate of the Raster.

Usage

From source file:org.geoserver.wps.gs.raster.algebra.JiffleScriptProcessTest.java

/**
 * Private method for ensuring the validity of the output image.
 * //from   w w  w  . j  a  va2 s  . c  om
 * @param outputImage RenderedImage extracted from the output coverage
 * @param inputCoverages Input Coverages used.
 * @param values
 */
private void checkExecution(RenderedImage outputImage, int[] values, GridCoverage2D... inputCoverages) {

    RenderedImage inputImage = inputCoverages[0].getRenderedImage();

    int numBands = outputImage.getSampleModel().getNumBands();

    int minTileX = outputImage.getMinTileX();
    int minTileY = outputImage.getMinTileY();
    int maxTileX = outputImage.getNumXTiles() + minTileX;
    int maxTileY = outputImage.getNumYTiles() + minTileY;

    int minX;
    int minY;
    int maxX;
    int maxY;

    Raster inputTile;
    Raster outputTile;

    int inputValue;
    int outputValue;
    // Cycle on each tile
    int valueOver0;

    for (int b = 0; b < numBands; b++) {

        valueOver0 = values[b];

        for (int xTile = minTileX; xTile < maxTileX; xTile++) {
            for (int yTile = minTileY; yTile < maxTileY; yTile++) {

                inputTile = inputImage.getTile(xTile, yTile);
                outputTile = outputImage.getTile(xTile, yTile);

                minX = inputTile.getMinX();
                minY = inputTile.getMinY();

                maxX = inputTile.getWidth() + minX;
                maxY = inputTile.getHeight() + minY;
                // Cycle on the x axis
                for (int x = minX; x < maxX; x++) {
                    // Cycle on the y axis
                    for (int y = minY; y < maxY; y++) {
                        inputValue = inputTile.getSample(x, y, b);
                        outputValue = outputTile.getSample(x, y, b);
                        // Check if the script operation is performed correctly
                        if (inputValue > 0) {
                            assertEquals(outputValue, valueOver0);
                        } else {
                            assertEquals(outputValue, LESS_THAN_ZERO_BAND_0);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java

@Test
//    @Ignore/*w w w.j  a  v  a  2 s .co m*/
public void testRequestInHole() throws Exception {
    final AbstractGridFormat format = TestUtils.getFormat(rgbAURL);
    final ImageMosaicReader reader = TestUtils.getReader(rgbAURL, format);

    assertNotNull(reader);

    // ask to extract an area that is inside the coverage bbox, but in a hole (no data)
    final ParameterValue<GridGeometry2D> ggp = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    Envelope2D env = new Envelope2D(reader.getCrs(), 500000, 3200000, 1000, 1000);
    GridGeometry2D gg = new GridGeometry2D(new GridEnvelope2D(0, 0, 100, 100), (Envelope) env);
    ggp.setValue(gg);

    // red background
    final ParameterValue<double[]> bgp = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
    bgp.setValue(new double[] { 255, 0, 0, 255 });

    // read and check we actually got a coverage in the requested area
    GridCoverage2D coverage = reader.read(new GeneralParameterValue[] { ggp, bgp });
    assertNotNull(coverage);
    assertTrue(coverage.getEnvelope2D().intersects((Rectangle2D) env));

    // and that the color is the expected one given the background values provided
    RenderedImage ri = coverage.getRenderedImage();
    int[] pixel = new int[4];
    Raster tile = ri.getTile(ri.getMinTileX() + 1, ri.getMinTileY() + 1);
    tile.getPixel(tile.getMinX(), tile.getMinY(), pixel);
    assertEquals(255, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    assertEquals(255, pixel[3]);
}

From source file:org.mrgeo.data.raster.RasterWritable.java

private static byte[] rasterToBytes(final Raster raster) {
    final int datatype = raster.getTransferType();

    byte[] pixels;

    final Object elements = raster.getDataElements(raster.getMinX(), raster.getMinY(), raster.getWidth(),
            raster.getHeight(), null);/*from   w w w .  java2 s  .co  m*/

    switch (datatype) {
    case DataBuffer.TYPE_BYTE: {
        pixels = (byte[]) elements;
        break;
    }
    case DataBuffer.TYPE_FLOAT: {
        final float[] floatElements = (float[]) elements;

        pixels = new byte[floatElements.length * RasterUtils.FLOAT_BYTES];

        final ByteBuffer bytebuff = ByteBuffer.wrap(pixels);
        final FloatBuffer floatbuff = bytebuff.asFloatBuffer();
        floatbuff.put(floatElements);

        break;
    }
    case DataBuffer.TYPE_DOUBLE: {
        final double[] doubleElements = (double[]) elements;

        pixels = new byte[doubleElements.length * RasterUtils.DOUBLE_BYTES];

        final ByteBuffer bytebuff = ByteBuffer.wrap(pixels);
        final DoubleBuffer doubleBuff = bytebuff.asDoubleBuffer();
        doubleBuff.put(doubleElements);

        break;
    }
    case DataBuffer.TYPE_INT: {
        final int[] intElements = (int[]) elements;

        pixels = new byte[intElements.length * RasterUtils.INT_BYTES];

        final ByteBuffer bytebuff = ByteBuffer.wrap(pixels);
        final IntBuffer intBuff = bytebuff.asIntBuffer();
        intBuff.put(intElements);

        break;
    }
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_USHORT: {
        final short[] shortElements = (short[]) elements;

        pixels = new byte[shortElements.length * RasterUtils.SHORT_BYTES];

        final ByteBuffer bytebuff = ByteBuffer.wrap(pixels);
        final ShortBuffer shortbuff = bytebuff.asShortBuffer();
        shortbuff.put(shortElements);

        break;
    }
    default:
        throw new RasterWritableException("Error trying to append raster.  Bad raster data type");
    }

    return pixels;
}

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

public void calculateStats(final Raster r) {
    count = 0;//from   w ww  .ja  v  a2  s .c  o  m
    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;
}

From source file:org.photovault.image.RawConvOpImage.java

/**
 * Compute single tile of the image//from  w  w w . j a  v  a  2s.com
 * @param x
 * @param y
 * @return
 */
@Override
public Raster computeTile(int x, int y) {
    if (contrastLut == null) {
        createLumLut();
    }
    Raster r = source.getTile(x, y);
    WritableRaster w = r.createCompatibleWritableRaster(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight());
    int startX = r.getMinX();
    int startY = r.getMinY();
    for (int l = startY; l < startY + r.getHeight(); l++) {
        for (int c = startX; c < startX + r.getWidth(); c++) {
            long sr = r.getSample(c, l, 0);
            long sg = r.getSample(c, l, 1);
            long sb = r.getSample(c, l, 2);
            long avg = (sr + sg + sb) / 3;
            long m = contrastLut[(int) avg];
            long[] pixel = new long[3];
            pixel[0] = (sr * m) >> 16;
            pixel[1] = (sg * m) >> 16;
            pixel[2] = (sb * m) >> 16;
            long clippedSum = 0;
            long totalHeadroom = 0;
            boolean clipped[] = new boolean[3];
            int channelsClipped = 0;
            int channelsUnclipped = 0;
            for (int n = 0; n < 3; n++) {
                if (pixel[n] > 65535) {
                    channelsClipped++;
                    clipped[n] = true;
                    clippedSum += pixel[n] - 65535;
                } else {
                    clipped[n] = false;
                    totalHeadroom += 65536 - pixel[n];
                    channelsUnclipped++;
                }
            }
            if (channelsClipped > 0) {
                for (int n = 0; n < 3; n++) {
                    if (!clipped[n]) {
                        // Spread the clipped energy to other channels so that
                        // they reach saturation at the same time
                        long headroom = 65536 - pixel[n];
                        pixel[n] += clippedSum * headroom / totalHeadroom;
                    }
                }
            }
            //                while ( channelsClipped > 0 && clippedSum > 0 &&
            //                        channelsUnclipped > 0 ) {
            //                    long spreaded = 0;
            //                    long spreadPerChan = clippedSum / channelsUnclipped +1;
            //                    for ( int n = 0; n < 3; n++ ) {
            //                        if ( !clipped[n] ) {
            //                            long add = Math.min( spreadPerChan, 65536 - pixel[n] );
            //                            pixel[n] += add;
            //                            spreaded += add;
            //                            if ( pixel[n] > 65535 ) {
            //                                channelsUnclipped--;
            //                            }
            //                        }
            //                    }
            //                    clippedSum -= spreaded;
            //                }
            try {
                w.setSample(c, l, 0, Math.min(65535, pixel[0]));
                w.setSample(c, l, 1, Math.min(65535, pixel[1]));
                w.setSample(c, l, 2, Math.min(65535, pixel[2]));
            } catch (ArrayIndexOutOfBoundsException e) {
                log.error(e);
            }
        }
    }
    return w;
}