Search in sources :

Example 1 with LookupTableJAI

use of javax.media.jai.LookupTableJAI in project Lucee by lucee.

the class Image method paletteToARGB.

private static BufferedImage paletteToARGB(BufferedImage src) {
    IndexColorModel icm = (IndexColorModel) src.getColorModel();
    int bands = icm.hasAlpha() ? 4 : 3;
    byte[][] data = new byte[bands][icm.getMapSize()];
    if (icm.hasAlpha())
        icm.getAlphas(data[3]);
    icm.getReds(data[0]);
    icm.getGreens(data[1]);
    icm.getBlues(data[2]);
    LookupTableJAI rtable = new LookupTableJAI(data);
    return JAI.create("lookup", src, rtable).getAsBufferedImage();
}
Also used : Point(java.awt.Point) IndexColorModel(java.awt.image.IndexColorModel) LookupTableJAI(javax.media.jai.LookupTableJAI)

Example 2 with LookupTableJAI

use of javax.media.jai.LookupTableJAI in project vcell by virtualcell.

the class FRAPData method binarize.

private PlanarImage binarize(BufferedImage source) {
    PlanarImage planarSource = PlanarImage.wrapRenderedImage(source);
    double[][] minmaxArr = (double[][]) ExtremaDescriptor.create(planarSource, null, 1, 1, false, 1, null).getProperty("extrema");
    short[] lookupData = new short[0x010000];
    lookupData[(int) minmaxArr[1][0]] = 1;
    LookupTableJAI lookupTable = new LookupTableJAI(lookupData, true);
    planarSource = LookupDescriptor.create(planarSource, lookupTable, null).createInstance();
    return planarSource;
}
Also used : PlanarImage(javax.media.jai.PlanarImage) LookupTableJAI(javax.media.jai.LookupTableJAI)

Example 3 with LookupTableJAI

use of javax.media.jai.LookupTableJAI in project vcell by virtualcell.

the class VFrap_OverlayImageDisplayJAI method refreshImage.

public void refreshImage() {
    if (underlyingImage != null && highlightImage != null) {
        PlanarImage sourceOverlay = null;
        alphaImageUnderlying = makeAlpha(underlyingImage, .6f);
        alphaImageHightlight = makeAlpha(highlightImage, .3f);
        RenderedImage contrastEnhancedUnderlyingImage = underlyingImage;
        if (contrastFactor > 0) {
            // Contrast stretch
            double[][] minmaxArr = null;
            if (minmaxPixelValues != null) {
                minmaxArr = new double[][] { { minmaxPixelValues.getMin() }, { minmaxPixelValues.getMax() } };
            } else {
                minmaxArr = (double[][]) ExtremaDescriptor.create(underlyingImage, null, 1, 1, false, 1, null).getProperty("extrema");
            }
            if ((minmaxArr[1][0] - minmaxArr[0][0]) != 0) {
                double offset = (SCALE_MAX * minmaxArr[0][0]) / (minmaxArr[0][0] - minmaxArr[1][0]);
                double scale = (SCALE_MAX) / (minmaxArr[1][0] - minmaxArr[0][0]);
                contrastEnhancedUnderlyingImage = RescaleDescriptor.create(underlyingImage, new double[] { scale }, new double[] { offset }, null);
            }
            // enhance with gamma function
            if (contrastFactor > 1) {
                byte[] tableData = new byte[256];
                for (int i = 0; i < 256; i++) {
                    double normalizedWithGamma = Math.pow((i / 255.0), 1 / (1.0 + (contrastFactor - 1) / 5.0));
                    int val = (int) (normalizedWithGamma * 255);
                    if (val > 255) {
                        val = 255;
                    }
                    tableData[i] = (byte) (val & 0xFF);
                }
                LookupTableJAI table = new LookupTableJAI(tableData);
                contrastEnhancedUnderlyingImage = LookupDescriptor.create(contrastEnhancedUnderlyingImage, table, null);
            }
        }
        sourceOverlay = CompositeDescriptor.create(contrastEnhancedUnderlyingImage, highlightImage, alphaImageUnderlying, alphaImageHightlight, false, CompositeDescriptor.NO_DESTINATION_ALPHA, null);
        sourceOverlay = ScaleDescriptor.create(sourceOverlay, zoom, zoom, 0f, 0f, Interpolation.getInstance(Interpolation.INTERP_NEAREST), null);
        set(sourceOverlay, 0, 0);
    } else {
        set(new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB), 0, 0);
    }
}
Also used : RenderedImage(java.awt.image.RenderedImage) PlanarImage(javax.media.jai.PlanarImage) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) LookupTableJAI(javax.media.jai.LookupTableJAI)

Example 4 with LookupTableJAI

use of javax.media.jai.LookupTableJAI in project vcell by virtualcell.

the class UShortImage method binarize.

private static PlanarImage binarize(BufferedImage source) {
    PlanarImage planarSource = PlanarImage.wrapRenderedImage(source);
    double[][] minmaxArr = (double[][]) ExtremaDescriptor.create(planarSource, null, 1, 1, false, 1, null).getProperty("extrema");
    short[] lookupData = new short[0x010000];
    lookupData[(int) minmaxArr[1][0]] = 1;
    LookupTableJAI lookupTable = new LookupTableJAI(lookupData, true);
    planarSource = LookupDescriptor.create(planarSource, lookupTable, null).createInstance();
    return planarSource;
}
Also used : PlanarImage(javax.media.jai.PlanarImage) LookupTableJAI(javax.media.jai.LookupTableJAI)

Aggregations

LookupTableJAI (javax.media.jai.LookupTableJAI)4 PlanarImage (javax.media.jai.PlanarImage)3 Point (java.awt.Point)2 BufferedImage (java.awt.image.BufferedImage)1 IndexColorModel (java.awt.image.IndexColorModel)1 RenderedImage (java.awt.image.RenderedImage)1