Arrays.fill(floatDataArray[i], noDataValue.floatValue()); dataBuffer = new DataBufferFloat(floatDataArray, dataBufferSize); break; case DataBuffer.TYPE_DOUBLE:
@Override protected DataBufferFloat createDataBuffer( final FloatArray data ) { final float[] sourceArray = data.getCurrentStorageArray(); return new DataBufferFloat( sourceArray, sourceArray.length ); }
@Override protected DataBufferFloat createDataBuffer( final FloatArray data ) { final float[] sourceArray = data.getCurrentStorageArray(); return new DataBufferFloat( sourceArray, sourceArray.length ); }
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. * It is assumed that each channel corresponds to one element of the array. * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(float[][] data, int w, int h) { int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. * It is assumed that each channel corresponds to one element of the array. * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(float[][] data, int w, int h) { int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. * It is assumed that each channel corresponds to one element of the array. * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(float[][] data, int w, int h) { int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Constructs a {@linkplain GridType#LOCALIZATION localization} grid using the specified data. * This convenience method creates the intermediate {@link DataBufferFloat} object from the * supplied data assuming that the first valid values is located at index 0. If this is not * the case, user can create a {@code DataBufferFloat} object directly in order to gain more * control. * * @param width Number of columns in the grid. * @param height Number of rows in the grid. * @param data Data stored in <a href="http://en.wikipedia.org/wiki/Row-major_order">row-major * order</a>, one array for each target dimension. * @return The math transform backed by the given grid. */ public static GridTransform create(final int width, final int height, final float[]... data) { return create(GridType.LOCALIZATION, new DataBufferFloat(data, width*height), new Dimension(width, height), null); }
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. It is assumed that each channel * corresponds to one element of the array. For example, for RGB * data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(final float[][] data, final int w, final int h) { final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }
/** * Creates an image from the given single-precision floating point data. * * @param data Array containing image data. It is assumed that each channel * corresponds to one element of the array. For example, for RGB * data, data[0] is R, data[1] is G, and data[2] is B. * @param w Width of image plane. * @param h Height of image plane. */ public static BufferedImage makeImage(final float[][] data, final int w, final int h) { final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, data[0].length); return constructImage(data.length, dataType, w, h, false, true, buffer); }
public static BufferedImage imageFromArray(float[] input, int width, int height) { SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, width, height, 1, width, new int[]{0}); ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorModel colorModel = new ComponentColorModel(colorSpace, false, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT); DataBuffer buffer = new DataBufferFloat(width * height * 1); WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null); raster.setPixels(0, 0, width, height, input); return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null); }
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. For example, for RGB * data, the pattern "RGBRGBRGB..." is interleaved, while * "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(final float[] data, final int w, final int h, final int c, final boolean interleaved) { if (c == 1) return makeImage(data, w, h); final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, * while "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(float[] data, int w, int h, int c, boolean interleaved) { if (c == 1) return makeImage(data, w, h); int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, * while "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(float[] data, int w, int h, int c, boolean interleaved) { if (c == 1) return makeImage(data, w, h); int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, * while "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(float[] data, int w, int h, int c, boolean interleaved) { if (c == 1) return makeImage(data, w, h); int dataType = DataBuffer.TYPE_FLOAT; DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
/** * Creates an image from the given float data. * * @param data Array containing image data. * @param w Width of image plane. * @param h Height of image plane. * @param c Number of channels. * @param interleaved If set, the channels are assumed to be interleaved; * otherwise they are assumed to be sequential. For example, for RGB * data, the pattern "RGBRGBRGB..." is interleaved, while * "RRR...GGG...BBB..." is sequential. */ public static BufferedImage makeImage(final float[] data, final int w, final int h, final int c, final boolean interleaved) { if (c == 1) return makeImage(data, w, h); final int dataType = DataBuffer.TYPE_FLOAT; final DataBuffer buffer = new DataBufferFloat(data, c * w * h); return constructImage(c, dataType, w, h, interleaved, false, buffer); }
public static PlanarImage createFloatPlanarImage(float[] src, int width, int height){ int[] bandOffsets = {0}; SampleModel sampleModel = new PixelInterleavedSampleModel(TYPE_FLOAT, width, height, 1, width, bandOffsets); ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorModel colorModel = new ComponentColorModel(colorSpace, false, false, Transparency.TRANSLUCENT, TYPE_FLOAT); PlanarImage opImage; DataBuffer buffer = new DataBufferFloat(width * height); // Wrap it in a writable raster WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null); raster.setPixels(0, 0, width, height, src); // Create an image with this raster BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null); opImage = PlanarImage.wrapRenderedImage(image); return opImage; }
@Override public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params) throws ImageReadException, IOException { try (RgbeInfo info = new RgbeInfo(byteSource)) { // It is necessary to create our own BufferedImage here as the // org.apache.commons.imaging.common.IBufferedImageFactory interface does // not expose this complexity final DataBuffer buffer = new DataBufferFloat(info.getPixelData(), info.getWidth() * info.getHeight()); final BufferedImage ret = new BufferedImage(new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, buffer.getDataType()), Raster.createWritableRaster( new BandedSampleModel(buffer.getDataType(), info.getWidth(), info.getHeight(), 3), buffer, new Point()), false, null); return ret; } }
private Band createBand(String name, int dataType, int w, int h, float[] floats, Double noDataValue) { final SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, 1, w, new int[]{0}); final ColorModel cm = PlanarImage.createColorModel(sm); final TiledImage sourceImage = new TiledImage(0, 0, w, h, 0, 0, sm, cm); sourceImage.setData(WritableRaster.createWritableRaster(sm, new DataBufferFloat(floats, w * h), null)); final Band band = new Band(name, dataType, w, h); band.setSourceImage(sourceImage); if (noDataValue != null) { band.setNoDataValueUsed(true); band.setNoDataValue(noDataValue); } return band; } }
@Test public void testAccumulateDataFloat() throws Exception { float[] data = new float[]{18.6f, 18.5f, 18.4f, 18.3f, 18.2f, 18.1f, 18.0f, 17.9f, 17.8f, 17.7f, 17.6f}; SummaryStxOp op = new SummaryStxOp(); op.accumulateData(getPixels(new DataBufferFloat(data, data.length)), null); assertEquals(17.6, op.getMinimum(), 1.0e-6); assertEquals(18.6, op.getMaximum(), 1.0e-6); assertEquals(18.1, op.getMean(), 1.0e-6); assertEquals(0.11, op.getVariance(), 1.0e-6); assertEquals(0.331662, op.getStandardDeviation(), 1.0e-6); }
@Test public void testAccumulateWithOnlyNoData() throws Exception { float[] data = new float[11]; RenderedOp maskImage = ConstantDescriptor.create((float) data.length, 1.0f, new Byte[]{0}, null); SummaryStxOp op = new SummaryStxOp(); op.accumulateData(getPixels(new DataBufferFloat(data, data.length)), getPixels(maskImage)); assertEquals(Double.NaN, op.getMinimum(), 1.0e-6); assertEquals(Double.NaN, op.getMaximum(), 1.0e-6); assertEquals(Double.NaN, op.getMean(), 1.0e-6); assertEquals(Double.NaN, op.getVariance(), 1.0e-6); assertEquals(Double.NaN, op.getStandardDeviation(), 1.0e-6); }