Search in sources :

Example 6 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project vcell by virtualcell.

the class VFrap_OverlayImageDisplayJAI method makeAlpha.

/**
 * Method makeAlpha.
 * @param src RenderedImage
 * @param b float
 * @return RenderedImage
 */
private RenderedImage makeAlpha(RenderedImage src, float b) {
    // get color band
    int band = src.getColorModel().getNumColorComponents();
    // ignore alpha channel
    band = band > 3 ? 3 : band;
    // make alpha channel paramenter
    Byte[] bandValues = new Byte[band];
    for (int i = 0; i < band; i++) {
        bandValues[i] = new Byte((byte) (b * SCALE_MAX));
    }
    // make alpha channel paramenter
    ParameterBlock pb = new ParameterBlock();
    pb.add((float) src.getWidth());
    pb.add((float) src.getHeight());
    pb.add(bandValues);
    // make alpha channel
    return JAI.create("constant", pb, null);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) Point(java.awt.Point)

Example 7 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class JP2KakaduReadTest method displayStatistics.

public static void displayStatistics(boolean b, RenderedImage source) {
    PlanarImage img = JAI.create("extrema", source, null);
    double[] maximum = (double[]) img.getProperty("maximum");
    double[] minimum = (double[]) img.getProperty("minimum");
    ParameterBlock pb = (new ParameterBlock()).addSource(source);
    pb.add(null).add(1).add(1).add(new int[] { 65536 });
    pb.add(new double[] { minimum[0] }).add(new double[] { maximum[0] });
    PlanarImage dst = JAI.create("histogram", pb);
    Histogram h = (Histogram) dst.getProperty("hiStOgRam");
    JFrame frame = new HistogramFrame(h, b);
    frame.pack();
    frame.show();
}
Also used : Histogram(javax.media.jai.Histogram) ParameterBlock(java.awt.image.renderable.ParameterBlock) JFrame(javax.swing.JFrame) PlanarImage(javax.media.jai.PlanarImage)

Example 8 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class ImageIOUtilities method visualizeRescaled.

/**
 * Visualize the image, after rescaling its values, given a threshold for
 * the ROI. This is useful to rescale an image coming from a source which
 * may contain noDataValues. The ROI threshold allows to set a minimal value
 * to be included in the computation of the future JAI extrema operation
 * used before the JAI rescale operation.
 *
 * @param image
 *                RenderedImage to visualize
 * @param title
 *                title for the frame
 * @param roiThreshold
 *                the threshold for the inner ROI
 */
static void visualizeRescaled(RenderedImage image, String title, int roiThreshold) {
    ROI roi = new ROI(image, roiThreshold);
    ParameterBlock pb = new ParameterBlock();
    // The source image
    pb.addSource(image);
    if (roi != null)
        // The region of the image to scan
        pb.add(roi);
    // Perform the extrema operation on the source image
    RenderedOp op = JAI.create("extrema", pb);
    // Retrieve both the maximum and minimum pixel value
    double[][] extrema = (double[][]) op.getProperty("extrema");
    final double[] scale = new double[] { (255) / (extrema[1][0] - extrema[0][0]) };
    final double[] offset = new double[] { ((255) * extrema[0][0]) / (extrema[0][0] - extrema[1][0]) };
    // Preparing to rescaling values
    ParameterBlock pbRescale = new ParameterBlock();
    pbRescale.add(scale);
    pbRescale.add(offset);
    pbRescale.addSource(image);
    RenderedOp rescaledImage = JAI.create("Rescale", pbRescale);
    ParameterBlock pbConvert = new ParameterBlock();
    pbConvert.addSource(rescaledImage);
    pbConvert.add(DataBuffer.TYPE_BYTE);
    RenderedOp destImage = JAI.create("format", pbConvert);
    visualize(destImage, title);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) RenderedOp(javax.media.jai.RenderedOp) ROI(javax.media.jai.ROI)

Example 9 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class ImageReadPropertyGenerator method create.

/**
 * Type-safe convenience method for creating a {@link RenderedOp}
 * representing the "ImageRead" operation in rendered mode. The
 * method packs the parameters into a new <code>ParameterBlock</code>
 * and invokes {@link JAI#create(String,ParameterBlock,RenderingHints)}.
 *
 * @param input The input source.
 * @param imageChoice The index of the image to read.
 * @param readMetadata Whether metadata should be read if available.
 * @param readThumbnails Whether thumbnails should be read if available.
 * @param verifyInput Whether to verify the validity of the input source.
 * @param listeners EventListeners to be registered with the ImageReader.
 * @param locale The Locale for the ImageReader to use.
 * @param readParam Java Image I/O read parameter instance.
 * @param reader Java Image I/O reader instance.
 * @param hints Hints possibly including an <code>ImageLayout</code>.
 * @return an image derived from the input source.
 */
public static RenderedOp create(ImageInputStream input, Integer imageChoice, Boolean readMetadata, Boolean readThumbnails, Boolean verifyInput, EventListener[] listeners, Locale locale, EnhancedImageReadParam readParam, ImageReader reader, RenderingHints hints) {
    ParameterBlock args = new ParameterBlock();
    args.add(input);
    args.add(imageChoice);
    args.add(readMetadata);
    args.add(readThumbnails);
    args.add(verifyInput);
    args.add(listeners);
    args.add(locale);
    args.add(readParam);
    args.add(reader);
    return JAI.create(OPERATION_NAME, args, hints);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Example 10 with ParameterBlock

use of java.awt.image.renderable.ParameterBlock in project imageio-ext by geosolutions-it.

the class ImageReadPropertyGenerator method createRenderable.

/**
 * Type-safe convenience method for creating a {@link RenderableOp}
 * representing the "ImageRead" operation in renderable mode. The
 * method packs the parameters into a new <code>ParameterBlock</code>
 * and invokes
 * {@link JAI#createRenderable(String,ParameterBlock,RenderingHints)}.
 *
 * @param input The input source.
 * @param imageChoice The indices of the images to read.
 * @param readMetadata Whether metadata should be read if available.
 * @param readThumbnails Whether thumbnails should be read if available.
 * @param verifyInput Whether to verify the validity of the input source.
 * @param listeners EventListeners to be registered with the ImageReader.
 * @param locale The Locale for the ImageReader to use.
 * @param readParam Java Image I/O read parameter instance.
 * @param reader Java Image I/O reader instance.
 * @param hints Hints possibly including an <code>ImageLayout</code>.
 * @return an image capable of rendering an image from those in the
 * input source.
 */
public static RenderableOp createRenderable(ImageInputStream input, int[] imageChoice, Boolean readMetadata, Boolean readThumbnails, Boolean verifyInput, EventListener[] listeners, Locale locale, ImageReadParam readParam, ImageReader reader, RenderingHints hints) {
    ParameterBlock args = new ParameterBlock();
    args.add(input);
    args.add(imageChoice);
    args.add(readMetadata);
    args.add(readThumbnails);
    args.add(verifyInput);
    args.add(listeners);
    args.add(locale);
    args.add(readParam);
    args.add(reader);
    return JAI.createRenderable(OPERATION_NAME, args, hints);
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock)

Aggregations

ParameterBlock (java.awt.image.renderable.ParameterBlock)29 RenderingHints (java.awt.RenderingHints)5 RenderedImage (java.awt.image.RenderedImage)5 FileOpException (digilib.io.FileOpException)3 BufferedImage (java.awt.image.BufferedImage)3 Point (java.awt.Point)2 ColorModel (java.awt.image.ColorModel)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 DirectColorModel (java.awt.image.DirectColorModel)2 IndexColorModel (java.awt.image.IndexColorModel)2 PackedColorModel (java.awt.image.PackedColorModel)2 BorderExtender (javax.media.jai.BorderExtender)2 BorderExtenderConstant (javax.media.jai.BorderExtenderConstant)2 PlanarImage (javax.media.jai.PlanarImage)2 TransposeType (javax.media.jai.operator.TransposeType)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 AffineTransformOp (java.awt.image.AffineTransformOp)1 DataBufferByte (java.awt.image.DataBufferByte)1