/** * Returns the {@linkplain #getRenderedImage rendered image} after null operation. This * operation may be used for setting new ImageProperties or for applying new RenderingHints. * * @return The rendered operation. * @see #getRenderedImage * @see #getPlanarImage * @see #getImageAsROI */ public ImageWorker nullOp() { // Creating a parameter block ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // Executing the operation image = JAI.create("Null", pb, getRenderingHints()); return this; }
/** Scales the underlying raster using the provided parameters. */ public ImageWorker scale( double xScale, double yScale, double xTrans, double yTrans, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. double[] scalingParams = new double[] {xScale, yScale, xTrans, yTrans}; scale(pb, scalingParams, interp, getRenderingHints()); // getting the new ROI property updateROI(true, SCALE_OP_NAME); return this; }
/** * Loads an image using the provided file name and the {@linkplain #getRenderingHints current * hints}, which are used to control caching and layout. * * @param source Filename of the source image to read. * @param imageChoice Image index in multipage images. * @param readMatadata If {@code true}, metadata will be read. */ public final void load(final String source, final int imageChoice, final boolean readMetadata) { final ParameterBlockJAI pbj = new ParameterBlockJAI("ImageRead"); pbj.setParameter("Input", source) .setParameter("ImageChoice", Integer.valueOf(imageChoice)) .setParameter("ReadMetadata", Boolean.valueOf(readMetadata)) .setParameter("VerifyInput", Boolean.TRUE); image = JAI.create("ImageRead", pbj, getRenderingHints()); }
/** * Takes one rendered or renderable image and an array of integer constants, and performs a * bit-wise logical "xor" between every pixel in the same band of the source and the constant * from the corresponding array entry. See JAI {@link XorConstDescriptor} for details. * * @see XorConstDescriptor */ public final ImageWorker xorConst(int[] values) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); if (JAIExt.isJAIExtOperation(OPERATION_CONST_OP_NAME)) { double[] valuesD = new double[values.length]; for (int i = 0; i < values.length; i++) { valuesD[i] = values[i]; } prepareOpConstOperation(Operator.XOR, valuesD, pb, roi, nodata, true); image = JAI.create(OPERATION_CONST_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("XorConst", pb, getRenderingHints()); } // image = XorConstDescriptor.create(image, values, getRenderingHints()); invalidateStatistics(); return this; }
/** * Returns the {@linkplain #getRenderedImage rendered image} as a rendered operation. * * @return The rendered operation. * @see #getRenderedImage * @see #getPlanarImage * @see #getImageAsROI */ public final RenderedOp getRenderedOperation() { final RenderedImage image = getRenderedImage(); if (image instanceof RenderedOp) { return (RenderedOp) image; } // Creating a parameter block ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // Executing the operation return JAI.create("Null", pb, getRenderingHints()); }
/** * Retains inconditionnaly certain bands of {@linkplain #image}. All other bands (if any) are * discarded without any further processing. * * @param bands the bands to retain. * @return this {@link ImageWorker}. * @see #getNumBands * @see #retainFirstBand * @see BandSelectDescriptor */ public final ImageWorker retainBands(final int[] bands) { // ParameterBlock creation ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(bands, 0); image = JAI.create("BandSelect", pb, getRenderingHints()); return this; }
/** * Takes two rendered or renderable source images, and myltiply form each pixel the related * value of the second image, each one from each source image of the corresponding position and * band. See JAI {@link MultiplyDescriptor} for details. * * @param renderedImage the {@link RenderedImage} to be multiplied to this {@link ImageWorker}. * @return this {@link ImageWorker}. * @see MultiplyDescriptor */ public final ImageWorker multiply(RenderedImage renderedImage) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.setSource(renderedImage, 1); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { prepareAlgebricOperation(Operator.MULTIPLY, pb, roi, nodata, true); image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Multiply", pb, getRenderingHints()); } invalidateStatistics(); return this; }
/** * Takes two rendered or renderable source images, and adds every pair of pixels, one from each * source image of the corresponding position and band. See JAI {@link AddDescriptor} for * details. * * @param renderedImage the {@link RenderedImage} to be added to this {@link ImageWorker}. * @return this {@link ImageWorker}. * @see AddDescriptor */ public final ImageWorker addImage(final RenderedImage renderedImage) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.setSource(renderedImage, 1); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { prepareAlgebricOperation(Operator.SUM, pb, roi, nodata, true); image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Add", pb, getRenderingHints()); } // image = AddDescriptor.create(image, renderedImage, getRenderingHints()); invalidateStatistics(); return this; }
/** * Takes two rendered or renderable source images, and subtract form each pixel the related * value of the second image, each one from each source image of the corresponding position and * band. See JAI {@link AddDescriptor} for details. * * @param renderedImage the {@link RenderedImage} to be subtracted to this {@link ImageWorker}. * @return this {@link ImageWorker}. * @see SubtractDescriptor */ public final ImageWorker subtract(final RenderedImage renderedImage) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.setSource(renderedImage, 1); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { prepareAlgebricOperation(Operator.SUBTRACT, pb, roi, nodata, true); image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Subtract", pb, getRenderingHints()); } invalidateStatistics(); return this; }
/** Apply a rangeLookup operation on the underlying image. */ public ImageWorker rangeLookup(Object rangeLookup) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(rangeLookup, 0); pb.set(roi, 2); if (roi != null) { if (background != null && background.length > 0) { pb.set(background[0], 1); // We must set the new NoData value setNoData(RangeFactory.create(background[0], background[0])); } } if (JAIExt.isJAIExtOperation("RLookup")) { image = JAI.create("RLookup", pb, getRenderingHints()); } else { image = JAI.create("RangeLookup", pb, getRenderingHints()); } return this; }
/** Warps the underlying using the provided Warp object. */ public ImageWorker colorIndex(ColorIndexer indexer) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(indexer, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background, 3); } } image = JAI.create("ColorIndexer", pb, getRenderingHints()); return this; }
/** * 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) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(dataType, 0); image = JAI.create("Format", pb, getRenderingHints()); setNoData(RangeFactory.convert(nodata, dataType)); // All post conditions for this method contract. assert image.getSampleModel().getDataType() == dataType; return this; }
/** Apply a rescale operation on the underlying image. */ public ImageWorker bandCombine(double[][] coeff) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(coeff, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 3); } } image = JAI.create("BandCombine", pb, getRenderingHints()); return this; }
/** Warps the underlying raster using the provided Warp object. */ public ImageWorker warp(Warp warp, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(warp, 0); pb.set(interp, 1); pb.set(roi, 3); pb.set(nodata, 4); pb.set(background, 2); image = JAI.create("Warp", pb, getRenderingHints()); updateROI(true, null); return this; }
/** Apply a rescale operation on the underlying image. */ public ImageWorker rescale(double[] scale, double[] offset) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(scale, 0); // The per-band constants to multiply by. pb.set(offset, 1); // The per-band offsets to be added. pb.set(roi, 2); // ROI pb.set(nodata, 3); // NoData range if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 5); // destination No Data value } } image = JAI.create("Rescale", pb, getRenderingHints()); return this; }
public ImageWorker border( int leftPad, int rightPad, int topPad, int bottomPad, BorderExtender ext) { ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(leftPad); pb.add(rightPad); pb.add(topPad); pb.add(bottomPad); pb.add(ext); pb.add(nodata); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.add(background); } } image = JAI.create("Border", pb, getRenderingHints()); return this; }
/** Performs Lookup on the underlying image */ public ImageWorker lookup(LookupTable table) { // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(table, 0); pb.set(roi, 2); // Convert the NoData if (nodata != null) { nodata = RangeFactory.convert(nodata, image.getSampleModel().getDataType()); } pb.set(nodata, 3); if (isNoDataNeeded()) { if (background != null && background.length > 0) { pb.set(background[0], 1); } } image = JAI.create("Lookup", pb, getRenderingHints()); return this; }
/** * 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(); // ParameterBlock definition ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(type, 0); image = JAI.create("Format", pb, hints); setNoData(RangeFactory.convert(nodata, type)); } return this; }
/** Apply a Generic Piecewise operation on the underlying image. */ public ImageWorker piecewise(PiecewiseTransform1D transform, Integer bandIndex) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(transform, 0); pb.set(bandIndex, 1); pb.set(roi, 2); pb.set(nodata, 3); if (isNoDataNeeded()) { if (transform.hasGaps()) { // We must set the new NoData value setNoData( RangeFactory.create( transform.getDefaultValue(), transform.getDefaultValue())); } } image = JAI.create("GenericPiecewise", pb, getRenderingHints()); return this; }
/** Apply a Raster classification on the underlying image. */ public ImageWorker classify(ColorMapTransform domain1D, Integer bandIndex) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); // The source image. pb.set(domain1D, 0); pb.set(bandIndex, 1); pb.set(roi, 2); pb.set(nodata, 3); if (isNoDataNeeded()) { if (domain1D.hasGaps()) { // We must set the new NoData value setNoData( RangeFactory.create( domain1D.getDefaultValue(), domain1D.getDefaultValue())); } } image = JAI.create("RasterClassifier", pb, getRenderingHints()); return this; }