Refine search
/** * Reads an image from a GeoTIFF file. For more information, see <a * href="http://download.java.net/media/jai-imageio/javadoc/1.1/com/sun/media/jai/operator/ImageReadDescriptor.html#RenderedMode">ImageReadDescriptor</a> */ private static synchronized RenderedImage readImage(File inFile) throws IOException { final ParameterBlock readParams = new ParameterBlock(); ImageInputStreamSpi lSpi = ImageIOExt.getImageInputStreamSPI(inFile); PlanarImage lImage = null; ImageInputStream lImgIn = lSpi.createInputStreamInstance(inFile, false, null); readParams.add(lImgIn); readParams.add(0); readParams.add(Boolean.FALSE); readParams.add(Boolean.FALSE); readParams.add(Boolean.FALSE); readParams.add(null); readParams.add(null); readParams.add(null); readParams.add(READER_SPI.createReaderInstance()); lImage = JAI.create("ImageRead", readParams, null); final String lFileName = inFile.getName(); final int lExtIndex = lFileName.lastIndexOf('.'); final String lFileNameNoExt = lExtIndex < 0 ? lFileName : lFileName.substring(0, lExtIndex); lImage.setProperty("name", lFileNameNoExt); return lImage; }
/** * 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; }
/** * 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; }
public ImageWorker translate(float xTrans, float yTrans, Interpolation interp) { ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(xTrans); pb.add(yTrans); pb.add(interp); // do not use getRenderingHints() with translate, as it cannot deal with layout hints image = JAI.create("Translate", pb, commonHints); 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()); }
/** * Takes one rendered or renderable image and an array of double constants, and multiplies every * pixel of the same band of the source by the constant from the corresponding array entry. See * JAI {@link MultiplyConstDescriptor} for details. * * @param inValues The constants to be multiplied. * @return this {@link ImageWorker}. * @see MultiplyConstDescriptor */ public final ImageWorker multiplyConst(double[] inValues) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); if (JAIExt.isJAIExtOperation(OPERATION_CONST_OP_NAME)) { prepareOpConstOperation(Operator.MULTIPLY, inValues, pb, roi, nodata, true); image = JAI.create(OPERATION_CONST_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("MultiplyConst", pb, getRenderingHints()); } // image = MultiplyConstDescriptor.create(image, inValues, getRenderingHints()); invalidateStatistics(); return this; }
/** * 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; }
ParameterBlock pb = new ParameterBlock(); if (vectorReference != null) { pb.addSource(vectorReference.getAsImage()); handleMosaicThresholds( ROI_THRESHOLDS, rasterROIs.size() + (vectorReference != null ? 1 : 0))); RenderedImage roiMosaic = JAI.create("Mosaic", pb, getRenderingHints()); return new ROI(roiMosaic);
/** * Takes two rendered or renderable source images, and do an OR for each pixel images, 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 or(final RenderedImage renderedImage) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.setSource(renderedImage, 1); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { prepareAlgebricOperation(Operator.OR, pb, roi, nodata, true); image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Or", 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 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; }
ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(bands, 0); image = JAI.create("BandSelect", pb, getRenderingHints());
/** * 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; }
/** 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; }
/** 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; }
/** * 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; }
/** 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; }
/** 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; }
ParameterBlock pb = new ParameterBlock(); pb.setSource(source, 0); pb.set(x, 0); image = JAI.create("Crop", pb, commonHints); invalidateStatistics(); return this;