/** * Set the image background value * * @param background The image background. * @return This ImageWorker */ public final ImageWorker setBackground(final double[] background) { this.background = background; invalidateStatistics(); return this; }
/** * Forces the {@linkplain #image} color model to the {@linkplain ColorSpace#CS_GRAY GRAYScale * color space}. If the current color space is already of {@linkplain ColorSpace#TYPE_GRAY * type}, then this method does nothing. * * @return this {@link ImageWorker}. * @see #isColorSpaceGRAYScale * @see ColorConvertDescriptor */ public final ImageWorker forceColorSpaceGRAYScale() { if (!isColorSpaceRGB()) { final ColorModel cm = new ComponentColorModel( ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); forceColorModel(cm); invalidateStatistics(); } // All post conditions for this method contract. assert isColorSpaceGRAYScale(); return this; }
/** * Set the <cite>NoData Range</cite> for checking NoData during computation. * * @param nodata The new NoData Range. * @return This ImageWorker */ public final ImageWorker setNoData(final Range nodata) { this.nodata = nodata; if (nodata != null && image != null) { PlanarImage img = getPlanarImage(); img.setProperty(NoDataContainer.GC_NODATA, new NoDataContainer(nodata)); image = img; } else if (image != null) { PlanarImage img = getPlanarImage(); Object property = img.getProperty(NoDataContainer.GC_NODATA); if (property != null && property != Image.UndefinedProperty) { // this kind of property cannot be unset, but it's possible to set it to // an invalid value img.setProperty(NoDataContainer.GC_NODATA, new Object()); image = img; } } invalidateStatistics(); return this; }
invalidateStatistics(); return this;
public final ImageWorker artifactsFilter(int threshold, int filterSize) { ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(roi, 0); pb.set(background, 1); pb.set(threshold, 2); pb.set(filterSize, 3); pb.set(nodata, 4); invalidateStatistics(); return this; }
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; }
/** * 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; }
/** Forces the provided {@link ColorModel} via the JAI ColorConvert operation. */ private void forceColorModel(final ColorModel cm) { final ImageLayout2 il = new ImageLayout2(image); il.setColorModel(cm); il.setSampleModel(cm.createCompatibleSampleModel(image.getWidth(), image.getHeight())); final RenderingHints oldRi = this.getRenderingHints(); final RenderingHints newRi = (RenderingHints) oldRi.clone(); newRi.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il)); setRenderingHints(newRi); // Setting the parameter blocks ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); pb.set(cm, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { // Elaborating the final NoData value if (background.length != cm.getNumColorComponents()) { throw new IllegalArgumentException("Wrong DestinationNoData value defined"); } pb.set(background, 3); } } image = JAI.create("ColorConvert", pb, getRenderingHints()); // restore RI this.setRenderingHints(oldRi); // invalidate stats invalidateStatistics(); }
pb.set(addAlpha, 4); this.image = JAI.create("BandMerge", pb, this.getRenderingHints()); invalidateStatistics();
/** * 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; }
/** * 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; }
/** * 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; }
invalidateStatistics(); return this;
/** * Inverts the pixel values of the {@linkplain #image}. * * @see InvertDescriptor */ public final ImageWorker invert() { // ParameterBlock creation ParameterBlock pb = new ParameterBlock(); pb.setSource(image, 0); if (JAIExt.isJAIExtOperation(ALGEBRIC_OP_NAME)) { pb.set(AlgebraDescriptor.Operator.INVERT, 0); pb.set(roi, 1); pb.set(nodata, 2); if (isNoDataNeeded()) { if (background != null && background.length > 0) { double dest = background[0]; pb.set(dest, 3); } } image = JAI.create(ALGEBRIC_OP_NAME, pb, getRenderingHints()); } else { image = JAI.create("Invert", pb, getRenderingHints()); } invalidateStatistics(); return this; }
pb.set(addAlpha, 4); this.image = JAI.create("BandMerge", pb, this.getRenderingHints()); invalidateStatistics();
sourceImage = JAI.create("bandmerge", pb); image = sourceImage; invalidateStatistics();