Java Code Examples for java.awt.image.Raster#getSampleFloat()

The following examples show how to use java.awt.image.Raster#getSampleFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VectorPainter.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
private static void averageRaster(WritableRaster raster, Raster count)
{
  for (int y = 0; y < raster.getHeight(); y++)
  {
    for (int x = 0; x < raster.getWidth(); x++)
    {
      for (int b = 0; b < raster.getNumBands(); b++)
      {
        float v = raster.getSampleFloat(x, y, b);
        float c = count.getSampleFloat(x, y, b);

        if (!Float.isNaN(v))
        {
          if (FloatUtils.isEqual(c, 0.0))
          {
            v = Float.NaN;
          }
          else
          {
            v /= c;
          }

          raster.setSample(x, y, b, v);
        }
      }
    }
  }
}
 
Example 2
Source File: MrGeoRasterTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
private void compareRaster(MrGeoRaster mrgeoraster, Raster raster)
{
  boolean intish = mrgeoraster.datatype() == DataBuffer.TYPE_BYTE || mrgeoraster.datatype() == DataBuffer.TYPE_INT
      || mrgeoraster.datatype() == DataBuffer.TYPE_SHORT || mrgeoraster.datatype() == DataBuffer.TYPE_USHORT;

  for (int b = 0; b < mrgeoraster.bands(); b++)
  {
    for (int y = 0; y < mrgeoraster.height(); y++)
    {
      for (int x = 0; x < mrgeoraster.width(); x++)
      {
        float v1 = mrgeoraster.getPixelFloat(x, y, b);
        float v2 = raster.getSampleFloat(x, y, b);

        if (Float.isNaN(v1) != Float.isNaN(v2))
        {
          org.junit.Assert.assertEquals("Pixel NaN mismatch: px: " + x + " py: " + y
              + " b: " + b + " v1: " + v1 + " v2: " + v2, v1, v2, 0);
        }

        // make delta something reasonable relative to the data

        //NOTE: this formula is not very reliable.  An error of 2e-3f for pixel v1=1 fails, but passes for v1=2.
        float delta = intish ? 1.0001f : Math.max(Math.abs(v1 * 1e-3f), 1e-3f);
        org.junit.Assert.assertEquals("Pixel value mismatch: px: " + x + " py: " + y
            + " b: " + b + " v1: " + v1 + " v2: " + v2, v1, v2, delta);

      }
    }
  }
}