/******************************************************************************* * * @inheritDoc * ******************************************************************************/ protected PlanarImage execute (ForceRenderingOp operation, final EditableImage image, PlanarImage planarImage) { planarImage.getData(); return planarImage; } }
@Override protected PlanarImage execute (ForceRenderingOp operation, final EditableImage image, PlanarImage planarImage) { planarImage.getData(); return planarImage; } }
private void updateBounds() { Rectangle currentBounds = boundsList.remove(0); x1 = currentBounds.x; x2 = x1 + currentBounds.width; x = x1; y = currentBounds.y; y2 = currentBounds.y + currentBounds.height; for (int i = 0; i < sourceImages.length; i++) { sourceTiles[i] = sourceImages[i].getData(currentBounds); } }
private void updateBounds() { currentBounds = boundsList.remove(0); x1 = currentBounds.x; x2 = x1 + currentBounds.width; x = x1 - 1; y = currentBounds.y; y2 = currentBounds.y + currentBounds.height; for (int i = 0; i < sourceImages.length; i++) { sourceTiles[i] = sourceImages[i].getData(currentBounds); } }
/******************************************************************************* * Calculates the average pixel value of a given image. Only band 0 of the * image is used, and the result is always of <code>double</code> type * regardless of image source pixel base type * * @param source source image * @return average pixel value ******************************************************************************/ public static double jaiAverageValue(PlanarImage source) { Raster raster = source.getData(); double result = 0.0; for (int x=0; x<raster.getWidth(); x++) { for (int y=0; y<raster.getHeight(); y++) { result += raster.getSampleDouble(x, y, 0); } } result /= (raster.getWidth() * raster.getHeight()); return result; }
/******************************************************************************* * Calculates the average pixel value of a given image. Only band 0 of the * image is used, and the result is always of <code>double</code> type * regardless of image source pixel base type * * @param source source image * @return average pixel value ******************************************************************************/ public static double jaiAverageValue(PlanarImage source) { Raster raster = source.getData(); double result = 0.0; for (int x=0; x<raster.getWidth(); x++) { for (int y=0; y<raster.getHeight(); y++) { result += raster.getSampleDouble(x, y, 0); } } result /= (raster.getWidth() * raster.getHeight()); return result; }
private static void outputComplexImage(final PlanarImage image) { final int w = image.getWidth(); final int h = image.getHeight(); final Raster dftData = image.getData(); final double[] real = dftData.getSamples(0, 0, w, h, 0, (double[]) null); final double[] imag = dftData.getSamples(0, 0, w, h, 1, (double[]) null); System.out.println("Real part:"); for (double v : real) { System.out.print(v + ", "); } System.out.println(); System.out.println("Imaginary part:"); for (double v : imag) { System.out.print(v + ", "); } System.out.println(); }
@Override @Nonnull protected Raster getRaster (final @Nonnull EditableImage image) { return image.getInnerProperty(PlanarImage.class).getData(); } }
private static double getSample(PlanarImage image, int x, int y) { return image.getData().getSampleDouble(x, y, 0); }
private void writeRawTiles(File levelDir, PlanarImage image, int tileWidth, int tileHeight, int numXTiles, int numYTiles, boolean rawZip) throws IOException { for (int tileY = 0; tileY < numYTiles; tileY++) { for (int tileX = 0; tileX < numXTiles; tileX++) { final int x = tileX * tileWidth; final int y = tileY * tileHeight; final Raster raster = image.getData(new Rectangle(x, y, tileWidth, tileHeight)); // todo - only "int" currently supported! check for other types!!! int[] data = ((DataBufferInt) raster.getDataBuffer()).getData(); if (data.length != tileWidth * tileHeight) { data = new int[tileWidth * tileHeight]; raster.getDataElements(x, y, tileWidth, tileHeight, data); } writeRawData(levelDir, tileX, tileY, data, rawZip); } } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public EditableImage createCopy (final boolean copyContents) { final TiledImage image2 = new TiledImage(getPlanarImage(), false); if (copyContents) { image2.setData(getPlanarImage().getData()); // FIXME: getData() creates a copy! } return createImage(image2); }
@Override protected PlanarImage execute (PadBlackOp operation, final EditableImage image, PlanarImage planarImage) { ParameterBlock pb = new ParameterBlock(); int width = planarImage.getData().getWidth(); int height = planarImage.getData().getHeight(); int padx = width; int pady = height; pb.addSource(planarImage); pb.add(padx); pb.add(padx); pb.add(pady); pb.add(pady); pb.add(BorderExtender.createInstance(BorderExtender.BORDER_ZERO)); planarImage = JAI.create("border", pb); JAIUtils.logImage(log, ">>>> PadBlackOp returning", planarImage); return planarImage; } }
/** * Performs the table lookup operation within the specified bounds. */ protected void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect) { // ROI bounds calculations Raster tile = sources[0]; Rectangle rect = tile.getBounds(); // ROI calculation if roiAccessor is used if (useRoiAccessor) { // Note that the getExtendedData() method is not called because the input images are padded. // For each image there is a check if the rectangle is contained inside the source image; // if this not happen, the data is taken from the padded image. Raster roi = null; if (srcROIImage.getBounds().contains(rect)) { roi = srcROIImage.getData(rect); } else { roi = srcROIImgExt.getData(rect); } lookupTable.lookup(sources[0], dest, destRect, roi); } else { lookupTable.lookup(sources[0], dest, destRect, null); } }
/******************************************************************************* * * @inheritDoc * ******************************************************************************/ protected PlanarImage execute (PadBlackOp operation, final EditableImage image, PlanarImage planarImage) { ParameterBlock pb = new ParameterBlock(); int width = planarImage.getData().getWidth(); int height = planarImage.getData().getHeight(); int padx = width; int pady = height; pb.addSource(planarImage); pb.add(padx); pb.add(padx); pb.add(pady); pb.add(pady); pb.add(BorderExtender.createInstance(BorderExtender.BORDER_ZERO)); planarImage = JAI.create("border", pb); JAIUtils.logImage(logger, ">>>> PadBlackOp returning", planarImage); return planarImage; } }
/******************************************************************************* * * @inheritDoc * ******************************************************************************/ public EditableImage createCopy (boolean copyContents) { TiledImage image2 = new TiledImage(getPlanarImage(), false); if (copyContents) { image2.setData(getPlanarImage().getData()); // FIXME: getData() creates a copy! } return createImage(image2); }
/** * Performs the table lookup operation within the specified bounds. */ protected void computeRect(Raster[] sources, WritableRaster dest, Rectangle destRect) { // ROI bounds calculations Raster tile = sources[0]; Rectangle rect = tile.getBounds(); // ROI calculation if roiAccessor is used if (useRoiAccessor) { // Note that the getExtendedData() method is not called because the input images are padded. // For each image there is a check if the rectangle is contained inside the source image; // if this not happen, the data is taken from the padded image. Raster roi = null; if (srcROIImage.getBounds().contains(rect)) { roi = srcROIImage.getData(rect); } else { roi = srcROIImgExt.getData(rect); } lookupTable.lookup(sources[0], dest, destRect, roi); } else { lookupTable.lookup(sources[0], dest, destRect, null); } }
@Override protected PlanarImage execute (PadPeriodicOp operation, final EditableImage image, PlanarImage planarImage) { int oldWidth = planarImage.getData().getWidth(); int oldHeight = planarImage.getData().getHeight(); int newWidth = JAIUtils.closestPower2Size(oldWidth); int newHeight = JAIUtils.closestPower2Size(oldHeight); int padx = (newWidth - oldWidth) / 2; int pady = (newHeight - oldHeight) / 2; log.debug(">>>> pad: {}, {}", padx, pady); ParameterBlock pb = new ParameterBlock(); pb.addSource(planarImage); pb.add((float)padx); pb.add((float)pady); RenderedOp trans = JAI.create("translate", pb); pb = new ParameterBlock(); pb.addSource(trans); pb.add(padx); pb.add(padx); pb.add(pady); pb.add(pady); pb.add(BorderExtender.createInstance(BorderExtender.BORDER_WRAP)); planarImage = JAI.create("border", pb); JAIUtils.logImage(log, ">>>> PadPeriodicJAIOp returning", planarImage); return planarImage; } }
ArrayDataProvider(RasterDataNode lonBand, RasterDataNode latBand, PlanarImage maskImage) { width = lonBand.getSceneRasterWidth(); int height = lonBand.getSceneRasterHeight(); MultiLevelImage lonImage = ImageManager.createMaskedGeophysicalImage(lonBand, Float.NaN); lonData = lonImage.getData().getSamples(0, 0, width, height, 0, (float[]) null); MultiLevelImage latImage = ImageManager.createMaskedGeophysicalImage(latBand, Float.NaN); latData = latImage.getData().getSamples(0, 0, width, height, 0, (float[]) null); if (maskImage != null) { final int[] maskValues = maskImage.getData().getSamples(0, 0, width, height, 0, (int[]) null); for (int i = 0; i < maskValues.length; i++) { if (maskValues[i] == 0) { lonData[i] = Float.NaN; latData[i] = Float.NaN; } } } }
static void accumulateTile(StxOp op, PlanarImage dataImage, PlanarImage maskImage, PixelAccessor dataAccessor, PixelAccessor maskAccessor, int tileX, int tileY) { final Raster dataTile = dataImage.getTile(tileX, tileY); if (!(dataTile instanceof NoDataRaster)) { // data and mask image might not have the same tile size // --> we can not use the tile index of the one for the other, so we use the bounds final Raster maskTile = maskImage != null ? maskImage.getData(dataTile.getBounds()) : null; final Rectangle rect = new Rectangle(dataImage.getMinX(), dataImage.getMinY(), dataImage.getWidth(), dataImage.getHeight()) .intersection(dataTile.getBounds()); final UnpackedImageData dataPixels = dataAccessor.getPixels(dataTile, rect, dataImage.getSampleModel().getDataType(), false); final UnpackedImageData maskPixels = maskAccessor != null ? maskAccessor.getPixels(maskTile, rect, DataBuffer.TYPE_BYTE, false) : null; op.accumulateData(dataPixels, maskPixels); } }
private void testIntMapOp(int sourceType, int[] sourceSamples, int expectedTargetType, int[] expectedTargetSamples) { final BufferedImage sourceImage = createSourceImage(sourceType, sourceSamples); final IntMap intMap = createIntMap(sourceImage); final PlanarImage targetImage = JAIUtils.createIndexedImage(sourceImage, intMap, 0); Assert.assertNotNull(targetImage); assertEquals(1, targetImage.getNumBands()); assertEquals(sourceImage.getWidth(), targetImage.getWidth()); assertEquals(sourceImage.getHeight(), targetImage.getHeight()); assertEquals(expectedTargetType, targetImage.getSampleModel().getDataType()); final Raster targetData = targetImage.getData(); final DataBuffer dataBuffer = targetData.getDataBuffer(); for (int i = 0; i < expectedTargetSamples.length; i++) { final int elem = dataBuffer.getElem(i); assertEquals("i=" + i, expectedTargetSamples[i], elem); } }