Search in sources :

Example 1 with UnsignedByteType

use of mpicbg.imglib.type.numeric.integer.UnsignedByteType in project TrakEM2 by trakem2.

the class IntegralImageMipMaps method wrap.

private static final Image<UnsignedByteType> wrap(final byte[] p, final int[] dims) {
    final Array<UnsignedByteType, ByteArray> c = new Array<UnsignedByteType, ByteArray>(new ArrayContainerFactory(), new ByteArray(p), dims, 1);
    final UnsignedByteType t = new UnsignedByteType(c);
    c.setLinkedType(t);
    return new Image<UnsignedByteType>(c, t);
}
Also used : ByteArray(mpicbg.imglib.container.basictypecontainer.array.ByteArray) Array(mpicbg.imglib.container.array.Array) UnsignedByteType(mpicbg.imglib.type.numeric.integer.UnsignedByteType) ByteArray(mpicbg.imglib.container.basictypecontainer.array.ByteArray) ArrayContainerFactory(mpicbg.imglib.container.array.ArrayContainerFactory) BufferedImage(java.awt.image.BufferedImage) FastIntegralImage(ini.trakem2.imaging.FastIntegralImage) IntegralImage(mpicbg.imglib.algorithm.integral.IntegralImage) Image(mpicbg.imglib.image.Image)

Example 2 with UnsignedByteType

use of mpicbg.imglib.type.numeric.integer.UnsignedByteType 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)

Example 3 with UnsignedByteType

use of mpicbg.imglib.type.numeric.integer.UnsignedByteType in project TrakEM2 by trakem2.

the class IntegralImageMipMaps method saa.

private static final ScaleAreaAveraging2d<LongType, UnsignedByteType> saa(final byte[] b, final int[] dims) {
    final IntegralImage<UnsignedByteType, LongType> ii = new IntegralImage<UnsignedByteType, LongType>(wrap(b, dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
    ii.process();
    return new ScaleAreaAveraging2d<LongType, UnsignedByteType>(ii.getResult(), new UnsignedByteType(), dims);
}
Also used : LongType(mpicbg.imglib.type.numeric.integer.LongType) FastIntegralImage(ini.trakem2.imaging.FastIntegralImage) IntegralImage(mpicbg.imglib.algorithm.integral.IntegralImage) ScaleAreaAveraging2d(mpicbg.imglib.algorithm.integral.ScaleAreaAveraging2d) UnsignedByteType(mpicbg.imglib.type.numeric.integer.UnsignedByteType)

Example 4 with UnsignedByteType

use of mpicbg.imglib.type.numeric.integer.UnsignedByteType in project TrakEM2 by trakem2.

the class Patch method addAlphaMaskLocal.

/**
 * Add the given area, in local coordinates, to the alpha mask, using the given fill value.
 */
public void addAlphaMaskLocal(final Area aLocal, int value) {
    if (value < 0)
        value = 0;
    if (value > 255)
        value = 255;
    // 
    CoordinateTransform ct = null;
    if (hasCoordinateTransform() && null == (ct = getCT())) {
        return;
    }
    // When the area is larger than the image, sometimes the area fails to be set at all
    // Also, intersection accelerates calls to contains(x,y) for complex polygons
    final Area a = new Area(new Rectangle(0, 0, (int) (width + 1), (int) (height + 1)));
    a.intersect(aLocal);
    if (M.isEmpty(a)) {
        Utils.log("ROI does not intersect the active image!");
        return;
    }
    ByteProcessor mask = getAlphaMask();
    // Use imglib to bypass all the problems with ShapeROI
    // Create a Shape image with background and the Area on it with 'value'
    final int background = (null != mask && 255 == value) ? 0 : 255;
    final ShapeList<UnsignedByteType> shapeList = new ShapeList<UnsignedByteType>(new int[] { (int) width, (int) height, 1 }, new UnsignedByteType(background));
    shapeList.addShape(a, new UnsignedByteType(value), new int[] { 0 });
    final mpicbg.imglib.image.Image<UnsignedByteType> shapeListImage = new mpicbg.imglib.image.Image<UnsignedByteType>(shapeList, shapeList.getBackground(), "mask");
    ByteProcessor rmask = (ByteProcessor) ImageJFunctions.copyToImagePlus(shapeListImage, ImagePlus.GRAY8).getProcessor();
    if (hasCoordinateTransform()) {
        // inverse the coordinate transform
        final TransformMesh mesh = new TransformMesh(ct, meshResolution, o_width, o_height);
        final TransformMeshMapping mapping = new TransformMeshMapping(mesh);
        rmask = (ByteProcessor) mapping.createInverseMappedImageInterpolated(rmask);
    }
    if (null == mask) {
        // There wasn't a mask, hence just set it
        mask = rmask;
    } else {
        final byte[] b1 = (byte[]) mask.getPixels();
        final byte[] b2 = (byte[]) rmask.getPixels();
        // Whatever is not background in the new mask gets set on the old mask
        for (int i = 0; i < b1.length; i++) {
            // background pixel in new mask
            if (background == (b2[i] & 0xff))
                continue;
            // replace old pixel with new pixel
            b1[i] = b2[i];
        }
    }
    setAlphaMask(mask);
}
Also used : ByteProcessor(ij.process.ByteProcessor) TransformMeshMapping(mpicbg.trakem2.transform.TransformMeshMapping) UnsignedByteType(mpicbg.imglib.type.numeric.integer.UnsignedByteType) ShapeList(mpicbg.imglib.container.shapelist.ShapeList) Rectangle(java.awt.Rectangle) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) ExportBestFlatImage(mpicbg.trakem2.transform.ExportBestFlatImage) Area(java.awt.geom.Area) CoordinateTransform(mpicbg.trakem2.transform.CoordinateTransform) TransformMesh(mpicbg.trakem2.transform.TransformMesh) CoordinateTransformMesh(mpicbg.models.CoordinateTransformMesh)

Aggregations

UnsignedByteType (mpicbg.imglib.type.numeric.integer.UnsignedByteType)4 FastIntegralImage (ini.trakem2.imaging.FastIntegralImage)3 BufferedImage (java.awt.image.BufferedImage)3 IntegralImage (mpicbg.imglib.algorithm.integral.IntegralImage)3 ScaleAreaAveraging2d (mpicbg.imglib.algorithm.integral.ScaleAreaAveraging2d)2 Array (mpicbg.imglib.container.array.Array)2 ByteArray (mpicbg.imglib.container.basictypecontainer.array.ByteArray)2 LongType (mpicbg.imglib.type.numeric.integer.LongType)2 ByteProcessor (ij.process.ByteProcessor)1 Image (java.awt.Image)1 Rectangle (java.awt.Rectangle)1 Area (java.awt.geom.Area)1 ArrayContainerFactory (mpicbg.imglib.container.array.ArrayContainerFactory)1 ShapeList (mpicbg.imglib.container.shapelist.ShapeList)1 IntegerTypeConverter (mpicbg.imglib.function.IntegerTypeConverter)1 Image (mpicbg.imglib.image.Image)1 CoordinateTransformMesh (mpicbg.models.CoordinateTransformMesh)1 CoordinateTransform (mpicbg.trakem2.transform.CoordinateTransform)1 ExportBestFlatImage (mpicbg.trakem2.transform.ExportBestFlatImage)1 TransformMesh (mpicbg.trakem2.transform.TransformMesh)1