Search in sources :

Example 1 with IntegerTypeConverter

use of mpicbg.imglib.function.IntegerTypeConverter in project TrakEM2 by trakem2.

the class IntegralImageMipMaps method createGRAY8.

@SuppressWarnings({ "unused", "unchecked", "null" })
private static final BufferedImage[] createGRAY8(final Patch patch, final ByteProcessor ip, final ByteProcessor mask) {
    final int w = ip.getWidth();
    final int h = ip.getHeight();
    final int[] dims = new int[] { w, h };
    final ScaleAreaAveraging2d<LongType, UnsignedByteType> saai, saam;
    {
        // Integral of the image
        final IntegralImage<UnsignedByteType, LongType> oa = new IntegralImage<UnsignedByteType, LongType>(wrap((byte[]) ip.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
        oa.process();
        saai = new ScaleAreaAveraging2d<LongType, UnsignedByteType>(oa.getResult(), new UnsignedByteType(), dims);
        // Integral of the mask, if any
        if (null != mask) {
            final IntegralImage<UnsignedByteType, LongType> ma = new IntegralImage<UnsignedByteType, LongType>(wrap((byte[]) mask.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
            ma.process();
            saam = new ScaleAreaAveraging2d<LongType, UnsignedByteType>(ma.getResult(), new UnsignedByteType(), dims);
        } else {
            saam = null;
        }
    }
    // Generate images
    final BufferedImage[] bis = new BufferedImage[Loader.getHighestMipMapLevel(patch) + 1];
    // 
    if (null == saam) {
        // mask is null
        // Save images as grayscale
        // sharing the byte[]
        bis[0] = ImageSaver.createGrayImage((byte[]) ip.getPixels(), w, h);
        for (int i = 1; i < bis.length; i++) {
            final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K;
            // An image of the scaled size
            saai.setOutputDimensions(wk, hk);
            saai.process();
            bis[i] = ImageSaver.createGrayImage(((Array<UnsignedByteType, ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), wk, hk);
        }
    } else {
        // Save images as RGBA, where all 3 color channels are the same
        bis[0] = ImageSaver.createARGBImage(blend((byte[]) ip.getPixels(), (byte[]) mask.getPixels()), w, h);
        for (int i = 1; i < bis.length; i++) {
            final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K;
            // An image of the scaled size
            saai.setOutputDimensions(wk, hk);
            saai.process();
            // A mask of the scaled size
            saam.setOutputDimensions(wk, hk);
            saam.process();
            // 
            bis[i] = ImageSaver.createARGBImage(blend(((Array<UnsignedByteType, ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), ((Array<UnsignedByteType, ByteArray>) saam.getResult().getContainer()).update(null).getCurrentStorageArray()), wk, hk);
        }
    }
    return bis;
}
Also used : LongType(mpicbg.imglib.type.numeric.integer.LongType) UnsignedByteType(mpicbg.imglib.type.numeric.integer.UnsignedByteType) BufferedImage(java.awt.image.BufferedImage) ByteArray(mpicbg.imglib.container.basictypecontainer.array.ByteArray) Array(mpicbg.imglib.container.array.Array) FastIntegralImage(ini.trakem2.imaging.FastIntegralImage) IntegralImage(mpicbg.imglib.algorithm.integral.IntegralImage) ScaleAreaAveraging2d(mpicbg.imglib.algorithm.integral.ScaleAreaAveraging2d) ByteArray(mpicbg.imglib.container.basictypecontainer.array.ByteArray) IntegerTypeConverter(mpicbg.imglib.function.IntegerTypeConverter)

Aggregations

FastIntegralImage (ini.trakem2.imaging.FastIntegralImage)1 BufferedImage (java.awt.image.BufferedImage)1 IntegralImage (mpicbg.imglib.algorithm.integral.IntegralImage)1 ScaleAreaAveraging2d (mpicbg.imglib.algorithm.integral.ScaleAreaAveraging2d)1 Array (mpicbg.imglib.container.array.Array)1 ByteArray (mpicbg.imglib.container.basictypecontainer.array.ByteArray)1 IntegerTypeConverter (mpicbg.imglib.function.IntegerTypeConverter)1 LongType (mpicbg.imglib.type.numeric.integer.LongType)1 UnsignedByteType (mpicbg.imglib.type.numeric.integer.UnsignedByteType)1