java.awt.image.Raster.getSampleFloat()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中java.awt.image.Raster.getSampleFloat方法的一些代码示例,展示了Raster.getSampleFloat的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Raster.getSampleFloat方法的具体详情如下:
包路径:java.awt.image.Raster
类名称:Raster
方法名:getSampleFloat

Raster.getSampleFloat介绍

暂无

代码示例

代码示例来源:origin: geoserver/geoserver

ps.print(raster.getSampleDouble(i, j, band));
else if (raster.getTransferType() == DataBuffer.TYPE_FLOAT)
  ps.print(raster.getSampleFloat(i, j, band));
else ps.print(raster.getSample(i, j, band));
if (i < (raster.getMinX() + raster.getWidth() - 1)) {

代码示例来源:origin: Geomatys/geotoolkit

/**
 * {@inheritDoc }.
 */
@Override
public float getSampleFloat() {
  return currentRaster.getSampleFloat(x, y, band);
}

代码示例来源:origin: apache/sis

/**
 * Returns the sample value in the specified band of current pixel as a single-precision floating point number.
 * This method assumes that {@link #next()} or {@link #moveTo(int,int)} has been invoked.
 */
@Override
public float getSampleFloat(final int band) {
  return currentRaster.getSampleFloat(x, y, band);
}

代码示例来源:origin: bcdev/beam

@Override
float[] createSamples() {
  float[] samples = new float[sourceTiles.length];
  for (int i = 0; i < samples.length; i++) {
    samples[i] = sourceTiles[i].getSampleFloat(x, y, 0);
  }
  return samples;
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * {@inheritDoc }.
 */
@Override
public float getSampleFloat() {
  return currentRaster.getSampleFloat(x, y, band);
}

代码示例来源:origin: bcdev/beam

@Override
public float[] createSamples() {
  if (hasSampleLocationChanged(x, y)) {
    lastX = x;
    lastY = y;
    for (int i = 0; i < lastSamples.length; i++) {
      lastSamples[i] = sourceTiles[i].getSampleFloat(x, y, 0);
    }
  }
  return lastSamples;
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Returns the sample value at the current position, as a floating point number.
 *
 * @return the sample value at the current position.
 *
 * @see Raster#getSampleFloat(int, int, int)
 * @see DataBuffer#TYPE_FLOAT
 */
public float getSampleFloat() {
  return raster.getSampleFloat(x, y, getBand());
}

代码示例来源:origin: bcdev/beam

@Override
public float getSampleFloat(int x, int y) {
  float sample = raster.getSampleFloat(x, y, 0);
  // handle unsigned data types, see also [BEAM-1147] (nf - 20100527)
  if (signedByte) {
    //noinspection SillyAssignment
    sample = (byte) sample;
  }
  if (scaled) {
    sample = toGeoPhysical(sample);
  }
  return sample;
}

代码示例来源:origin: bcdev/beam

private float interpolate(float wx, float wy, Raster raster, int band) {
  final int x0 = raster.getMinX();
  final int x1 = x0 + 1;
  final int y0 = raster.getMinY();
  final int y1 = y0 + 1;
  final float d00 = raster.getSampleFloat(x0, y0, band);
  final float d10 = raster.getSampleFloat(x1, y0, band);
  final float d01 = raster.getSampleFloat(x0, y1, band);
  final float d11 = raster.getSampleFloat(x1, y1, band);
  if (band == 0) {
    // lat
    return MathUtils.interpolate2D(wx, wy, d00, d10, d01, d11);
  } else {
    // lon
    return GeoCodingFactory.interpolateLon(wx, wy, d00, d10, d01, d11);
  }
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Returns the sample value at the specified row and column.
 */
public Object getValueAt(int y, int x) {
  final Raster raster = getRasterAt(y+=minY, x+=minX);
  if (raster == null) {
    return null;
  }
  switch (dataType) {
    default:                      return new Integer(raster.getSample      (x,y,band));
    case DataBuffer.TYPE_FLOAT:   return new Float  (raster.getSampleFloat (x,y,band));
    case DataBuffer.TYPE_DOUBLE:  return new Double (raster.getSampleDouble(x,y,band));
  }
}

代码示例来源:origin: org.geoserver/wcs

public void encode(OutputStream output) throws ServiceException, IOException {
  PrintStream ps = new PrintStream(output);
  ps.println("Grid bounds: " + coverage.getEnvelope());
  ps.println("Grid CRS: " + coverage.getCoordinateReferenceSystem());
  ps.println("Grid range: " + coverage.getGridGeometry().getGridRange());
  ps.println("Grid to world: " + coverage.getGridGeometry().getGridToCRS());
  ps.println("Contents:");
  RenderedImage ri = coverage.getRenderedImage();
  Raster raster = ri.getData();
  for(int band = 0; band < raster.getNumBands(); band++) {
    ps.println("Band " + band + ":");
    for (int j = raster.getMinY(); j < (raster.getMinY() +  raster.getHeight()); j++) {
      for (int i = raster.getMinX(); i < (raster.getMinX() +  raster.getWidth()); i++) {
        if(raster.getTransferType() == DataBuffer.TYPE_DOUBLE)
          ps.print(raster.getSampleDouble(i, j, band));
        else if(raster.getTransferType() == DataBuffer.TYPE_FLOAT)
          ps.print(raster.getSampleFloat(i, j, band));
        else
          ps.print(raster.getSample(i, j, band));
        if(i < (raster.getMinX() +  raster.getWidth() - 1));
          ps.print(" ");
      }
      ps.println();
    }
        }
  ps.flush();
}

代码示例来源:origin: bcdev/beam

private void getGeoPosInternal(int pixelX, int pixelY, GeoPos geoPos) {
  if (useTiling) {
    final int x = latLonImage.getMinX() + pixelX;
    final int y = latLonImage.getMinY() + pixelY;
    Raster data = latLonImage.getData(new Rectangle(x, y, 1, 1));
    float lat = data.getSampleFloat(x, y, 0);
    float lon = data.getSampleFloat(x, y, 1);
    geoPos.setLocation(lat, lon);
  } else {
    int i = rasterWidth * pixelY + pixelX;
    final float lat = latGrid.getRasterData().getElemFloatAt(i);
    final float lon = lonGrid.getRasterData().getElemFloatAt(i);
    geoPos.setLocation(lat, lon);
  }
}

代码示例来源:origin: bcdev/beam

/**
 * Gets a geo-physical sample value at the given pixel coordinate as {@code float} value.
 * <p/>
 * <i>Note: This method does not belong to the public API.
 * It has been added by Norman (2011-08-09) in order to perform performance tests.</i>
 *
 * @param x pixel X coordinate
 * @param y pixel Y coordinate
 * @return The geo-physical sample value.
 */
public float getSampleFloat(int x, int y) {
  final PlanarImage image = getGeophysicalImage();
  int tx = image.XToTileX(x);
  int ty = image.YToTileY(y);
  Raster tile = image.getTile(tx, ty);
  return tile.getSampleFloat(x, y, 0);
}

代码示例来源:origin: org.jaitools/jt-utils

/**
 * Gets the image value for the given image position as a float.
 *
 * @param x X ordinate
 * @param y Y ordinate
 * @param b band index
 *
 * @return image value
 * @throws PixelOutsideImageException  
 */
public float getSampleFloat(int x, int y, int b) throws PixelOutsideImageException {
  int tileX = XToTileX(x);
  int tileY = YToTileY(y);
  Raster t = getTile(tileX, tileY);
  if (t == null) {
    throw new PixelOutsideImageException(x, y, b);
  }
  return t.getSampleFloat(x, y, b);
}

代码示例来源:origin: bcdev/beam

private void testFloat() {
  final RenderedImage image = createImage(ProductData.TYPE_FLOAT32, DataBuffer.TYPE_FLOAT,
                      new float[]{1.2f, 5.6f, -12.6f, -12345.6f});
  assertEquals(1.2f, image.getData().getSampleFloat(0, 0, 0), 1e-6);
  assertEquals(5.6f, image.getData().getSampleFloat(1, 0, 0), 1e-6);
  assertEquals(-12.6f, image.getData().getSampleFloat(0, 1, 0), 1e-6);
  assertEquals(-12345.6f, image.getData().getSampleFloat(1, 1, 0), 1e-6);
}

代码示例来源:origin: bcdev/beam

@Test
public void testAveraging() {
  final RenderedOp mosaicImage = MosaicDescriptor.create(sourceImages, MosaicDescriptor.MOSAIC_TYPE_BLEND,
                              alphaImages, null, null, null, null);
  final Raster data = mosaicImage.getData();
  float sample = data.getSampleFloat(0, 0, 0);
  assertEquals(5.1f, sample, 0.0f);
  sample = data.getSampleFloat(5, 5, 0);
  assertEquals(5.1f, sample, 0.0f);
}

代码示例来源:origin: bcdev/beam

private void assertSampleValuesFloat(Band b1Band, GeoPos[] geoPositions, float[] expectedValues) {
  GeoCoding geoCoding = b1Band.getGeoCoding();
  final Raster b1Raster = b1Band.getSourceImage().getData();
  for (int i = 0; i < geoPositions.length; i++) {
    PixelPos pp = geoCoding.getPixelPos(geoPositions[i], null);
    final float expectedValue = expectedValues[i];
    final float actualValue = b1Raster.getSampleFloat((int) pp.x, (int) pp.y, 0);
    final String message = String.format("At <%d>:", i);
    assertEquals(message, expectedValue, actualValue, 1.0e-6);
  }
}

代码示例来源:origin: bcdev/beam

@Test
  public void testMosaicUpdate() {
    final RenderedOp firstImage = MosaicDescriptor.create(Arrays.copyOf(sourceImages, 3),
                               MosaicDescriptor.MOSAIC_TYPE_BLEND,
                               Arrays.copyOf(alphaImages, 3), null, null, null, null);
    final PlanarImage[] alphaUpdateImages = {
        PlanarImage.wrapRenderedImage(ConstantDescriptor.create(10.0f, 10.0f, new Float[]{6.0f}, null)),
        PlanarImage.wrapRenderedImage(ConstantDescriptor.create(10.0f, 10.0f, new Float[]{4.0f}, null))
    };
    final RenderedImage[] sourceUpdateImages = {firstImage, sourceImages[3]};
    final RenderedOp updatedImage = MosaicDescriptor.create(sourceUpdateImages,
                                MosaicDescriptor.MOSAIC_TYPE_BLEND,
                                alphaUpdateImages, null, null, null, null);

    final Raster data = updatedImage.getData();
    float sample = data.getSampleFloat(0, 0, 0);
    assertEquals(5.1f, sample, 0.0f);
    sample = data.getSampleFloat(5, 5, 0);
    assertEquals(5.1f, sample, 0.0f);
  }
}

代码示例来源:origin: org.imajine.image/org-imajine-image-core

/***************************************************************************
 *
 *
 **************************************************************************/
private void assertFloatContents (final EditableImage image, final float... filler)
 {
  final Raster raster = getRaster(image);
  for (int b = 0; b < image.getBandCount(); b++)
   {
    for (int y = 0; y < image.getHeight(); y++)
     {
      for (int x = 0; x < image.getWidth(); x++)
       {
        float sample = raster.getSampleFloat(x, y, b);
        AssertJUnit.assertEquals(filler[b], sample);
       }
     }
   }
 }

代码示例来源:origin: bcdev/beam

private void testOp(Op op) {
  Product sourceProduct = new Product("test", "test", 10, 10);
  op.setSourceProduct(sourceProduct);
  op.bandName = "A";
  op.sampleValue = 0.5f;
  Product targetProduct = op.getTargetProduct();
  assertSame(targetProduct, sourceProduct);
  assertNotNull(targetProduct.getBand("A"));
  assertEquals(0.5f, targetProduct.getBand("A").getSourceImage().getData().getSampleFloat(0, 0, 0));
  op.sampleValue = -0.6f;
  op.update();
  Product targetProduct2 = op.getTargetProduct();
  assertSame(targetProduct2, targetProduct);
  assertNotNull(targetProduct2.getBand("A"));
  assertEquals(-0.6f, targetProduct2.getBand("A").getSourceImage().getData().getSampleFloat(0, 0, 0));
}

相关文章