private List<RenderedImage> createVariableCountImages(List<List<PlanarImage>> alphaImageList) { List<RenderedImage> variableCountImageList = new ArrayList<RenderedImage>(variables.length); for (List<PlanarImage> variableAlphaImageList : alphaImageList) { final RenderedImage countFloatImage = createImageSum(variableAlphaImageList); variableCountImageList.add(FormatDescriptor.create(countFloatImage, DataBuffer.TYPE_INT, null)); } return variableCountImageList; }
public static PlanarImage ColorToGray(PlanarImage i) { double[][] matrix = { {0.114D, 0.587D, 0.299D, 0.0D} }; if (i.getSampleModel().getNumBands() != 3) { throw new IllegalArgumentException("Image # bands <> 3"); } PlanarImage result = BandCombineDescriptor.create(i, matrix, null); result = FormatDescriptor.create(result, DataBuffer.TYPE_FLOAT, null); return result; }
/** * Formats the underlying image to the provided data type. * * @param dataType * to be used for this {@link FormatDescriptor} operation. * @return this {@link ImageWorker} */ public final ImageWorker format(final int dataType) { image = FormatDescriptor.create(image, new Integer(dataType), getRenderingHints()); // All post conditions for this method contract. assert image.getSampleModel().getDataType() == dataType; return this; }
private RenderedImage getImageWithTargetDataType(int targetDataType, Band subsetBand) { RenderedImage sourceImage = subsetBand.getSourceImage(); final int actualTargetBandDataType = sourceImage.getSampleModel().getDataType(); if (actualTargetBandDataType != targetDataType) { sourceImage = FormatDescriptor.create(sourceImage, targetDataType, null); } return sourceImage; }
/** * Formats the underlying image to the provided data type. * * @param dataType * to be used for this {@link FormatDescriptor} operation. * @return this {@link ImageWorker} */ public final ImageWorker format(final int dataType) { image = FormatDescriptor.create(image, dataType, getRenderingHints()); // All post conditions for this method contract. assert image.getSampleModel().getDataType() == dataType; return this; }
list.add(FormatDescriptor.create(updateImage, DataBuffer.TYPE_FLOAT, null));
public static RenderedImage createFormatOp(RenderedImage image, int dataType) { if (image.getSampleModel().getDataType() == dataType) { return PlanarImage.wrapRenderedImage(image); } return FormatDescriptor.create(image, dataType, createDefaultRenderingHints(image, null)); }
private double[][] computeExtrema(RenderedImage image1, RenderedImage image2) { RenderedImage int1 = FormatDescriptor.create(image1, DataBuffer.TYPE_SHORT, null); RenderedImage int2 = FormatDescriptor.create(image2, DataBuffer.TYPE_SHORT, null); RenderedImage diff = SubtractDescriptor.create(int1, int2, null); RenderedImage extremaImg = ExtremaDescriptor.create(diff, null, 1, 1, false, Integer.MAX_VALUE, null); double[][] extrema = (double[][]) extremaImg.getProperty("extrema"); return extrema; }
public static PlanarImage ColorToGray(PlanarImage i) { double[][] matrix = { {0.114D, 0.587D, 0.299D, 0.0D} }; if (i.getSampleModel().getNumBands() != 3) { throw new IllegalArgumentException("Image # bands <> 3"); } ParameterBlock pb = new ParameterBlock(); pb.addSource(i); pb.add(matrix); PlanarImage result = JAI.create("bandcombine", pb, null); result = FormatDescriptor.create(result, DataBuffer.TYPE_FLOAT, null); return result; }
/** * Remove the alpha band * * @param requestedBands */ private void removeAlpha(int requestedBands) { // Retrieving/Setting the ImageLayout final RenderingHints hints = getRenderingHints(); ImageLayout layout = null; if (hints.containsKey(JAI.KEY_IMAGE_LAYOUT)) { layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT); } else { layout = new ImageLayout(); hints.put(JAI.KEY_IMAGE_LAYOUT, layout); } // Forcing the colormodel with noAlpha final ColorModel colorModel = new ComponentColorModel( ColorSpace.getInstance(requestedBands == 3 ? ColorSpace.CS_sRGB : ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); SampleModel sm = colorModel.createCompatibleSampleModel(image.getWidth(), image.getHeight()); layout.setSampleModel(sm); // Forcing the output format to remove the alpha Band image = FormatDescriptor.create(image, DataBuffer.TYPE_BYTE, hints); }
/** * If the was not already tiled, tile it. Note that no tiling will be done * if 'getRenderingHints()' failed to suggest a tile size. This method is * for internal use by {@link #write} methods only. * * @return this {@link ImageWorker}. */ public final ImageWorker tile() { final RenderingHints hints = getRenderingHints(); final ImageLayout layout = getImageLayout(hints); if (layout.isValid(ImageLayout.TILE_WIDTH_MASK) || layout.isValid(ImageLayout.TILE_HEIGHT_MASK)) { final int type = image.getSampleModel().getDataType(); image = FormatDescriptor.create(image, new Integer(type), hints); } return this; }
void assertImagesEqual(final RenderedImage image1, final RenderedImage image2) { // Preliminar checks on image properties assertEquals(image1.getWidth(), image2.getWidth()); assertEquals(image1.getHeight(), image2.getHeight()); // pixel by pixel difference check RenderedImage int1 = FormatDescriptor.create(image1, DataBuffer.TYPE_SHORT, null); RenderedImage int2 = FormatDescriptor.create(image2, DataBuffer.TYPE_SHORT, null); RenderedImage diff = SubtractDescriptor.create(int1, int2, null); RenderedImage extremaImg = ExtremaDescriptor.create(diff, null, 1, 1, false, Integer.MAX_VALUE, null); double[][] extrema = (double[][]) extremaImg.getProperty("extrema"); for (int band = 0; band < extrema.length; band++) { assertEquals("Minimum should be 0", 0d, extrema[0][band], 1e-9); assertEquals("Maximum should be 0", 0d, extrema[1][band], 1e-9); } }
@Override protected RenderedImage createImage(int level) { ImageManager imageManager = ImageManager.getInstance(); RenderingHints rh = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance( BorderExtenderCopy.BORDER_COPY)); PlanarImage geophysicalImage = imageManager.getGeophysicalImage(getSource(), level); int dataBufferType = getDataType() == ProductData.TYPE_FLOAT64 ? DataBuffer.TYPE_DOUBLE : DataBuffer.TYPE_FLOAT; geophysicalImage = FormatDescriptor.create(geophysicalImage, dataBufferType, null); PlanarImage validMaskImage = imageManager.getValidMaskImage(getSource(), level); if (validMaskImage != null) { geophysicalImage = new FillConstantOpImage(geophysicalImage, validMaskImage, Float.NaN); } return createSourceLevelImage(geophysicalImage, level, rh); } };
/** * If the was not already tiled, tile it. Note that no tiling will be done * if 'getRenderingHints()' failed to suggest a tile size. This method is * for internal use by {@link #write} methods only. * * @return this {@link ImageWorker}. */ public final ImageWorker tile() { final RenderingHints hints = getRenderingHints(); final ImageLayout layout = getImageLayout(hints); if (layout.isValid(ImageLayout.TILE_WIDTH_MASK) || layout.isValid(ImageLayout.TILE_HEIGHT_MASK)) { final int type = image.getSampleModel().getDataType(); image = FormatDescriptor.create(image, type, hints); } return this; }
private static PlanarImage createByteFormatOp(RenderedImage src) { ColorModel cm = ImageUtils.create8BitGreyscaleColorModel(); SampleModel sm = cm.createCompatibleSampleModel(src.getTileWidth(), src.getTileHeight()); ImageLayout layout = new ImageLayout(src); layout.setColorModel(cm); layout.setSampleModel(sm); return FormatDescriptor.create(src, DataBuffer.TYPE_BYTE, createDefaultRenderingHints(src, layout)); }
private RenderedOp getBandSourceImage(int i) { RenderedOp bandImage = BandSelectDescriptor.create(sourceImage, new int[]{i}, null); int tileWidth = bandImage.getTileWidth(); int tileHeight = bandImage.getTileHeight(); ImageLayout imageLayout = new ImageLayout(); boolean noSourceImageTiling = tileWidth == bandImage.getWidth() && tileHeight == bandImage.getHeight(); if (noSourceImageTiling) { tileWidth = Math.min(bandImage.getWidth(), 512); tileHeight = Math.min(bandImage.getHeight(), 512); imageLayout.setTileWidth(tileWidth); imageLayout.setTileHeight(tileHeight); } imageLayout.setSampleModel(new SingleBandedSampleModel(bandImage.getSampleModel().getDataType(), tileWidth, tileHeight)); bandImage = FormatDescriptor.create(bandImage, bandImage.getSampleModel().getDataType(), new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout)); return bandImage; }
image= FormatDescriptor.create(
private void setTargetBandImages(Product product, List<RenderedImage> bandImages, List<RenderedImage> variableCountImageList) { for (int i = 0; i < variables.length; i++) { Variable outputVariable = variables[i]; product.getBand(outputVariable.getName()).setSourceImage(bandImages.get(i)); final String countBandName = getCountBandName(outputVariable); product.getBand(countBandName).setSourceImage(variableCountImageList.get(i)); } if (conditions != null) { for (Condition condition : conditions) { if (condition.isOutput()) { // The sum of all conditions of all sources is created. // 1.0 indicates condition is true and 0.0 indicates false. final RenderedImage sumImage = createConditionSumImage(condition); final RenderedImage reformattedImage = FormatDescriptor.create(sumImage, DataBuffer.TYPE_INT, null); RenderedImage condImage = reformattedImage; if (isUpdateMode()) { final RenderedImage updateimage = updateProduct.getBand(condition.getName()).getSourceImage(); condImage = AddDescriptor.create(reformattedImage, updateimage, null); } Band band = product.getBand(condition.getName()); band.setSourceImage(condImage); } } } }
DataBuffer.TYPE_BYTE : image.getSampleModel().getTransferType(); final RenderingHints hints = getRenderingHints(type); image = FormatDescriptor.create(image, new Integer(type), hints);