Search in sources :

Example 1 with LinearIntensityMap

use of org.janelia.intensity.LinearIntensityMap in project TrakEM2 by trakem2.

the class FSLoader method mapIntensities.

@SuppressWarnings("unchecked")
@Override
protected boolean mapIntensities(final Patch p, final ImagePlus imp) {
    final ImagePlus coefficients = new Opener().openImage(getUNUIdFolder() + "trakem2.its/" + createIdPath(Long.toString(p.getId()), "it", ".tif"));
    if (coefficients == null)
        return false;
    final ImageProcessor ip = imp.getProcessor();
    @SuppressWarnings({ "rawtypes" }) final LinearIntensityMap<FloatType> map = new LinearIntensityMap<FloatType>((FloatImagePlus) ImagePlusImgs.from(coefficients));
    @SuppressWarnings("rawtypes") Img img;
    final long[] dims = new long[] { imp.getWidth(), imp.getHeight() };
    switch(p.getType()) {
        case ImagePlus.GRAY8:
        case // this only works for continuous color tables
        ImagePlus.COLOR_256:
            img = ArrayImgs.unsignedBytes((byte[]) ip.getPixels(), dims);
            break;
        case ImagePlus.GRAY16:
            img = ArrayImgs.unsignedShorts((short[]) ip.getPixels(), dims);
            break;
        case ImagePlus.COLOR_RGB:
            img = ArrayImgs.argbs((int[]) ip.getPixels(), dims);
            break;
        case ImagePlus.GRAY32:
            img = ArrayImgs.floats((float[]) ip.getPixels(), dims);
            break;
        default:
            img = null;
    }
    if (img == null)
        return false;
    map.run(img);
    return true;
}
Also used : ImageProcessor(ij.process.ImageProcessor) Img(net.imglib2.img.Img) LinearIntensityMap(org.janelia.intensity.LinearIntensityMap) ImagePlus(ij.ImagePlus) FloatImagePlus(net.imglib2.img.imageplus.FloatImagePlus) Opener(ij.io.Opener) FloatType(net.imglib2.type.numeric.real.FloatType)

Aggregations

ImagePlus (ij.ImagePlus)1 Opener (ij.io.Opener)1 ImageProcessor (ij.process.ImageProcessor)1 Img (net.imglib2.img.Img)1 FloatImagePlus (net.imglib2.img.imageplus.FloatImagePlus)1 FloatType (net.imglib2.type.numeric.real.FloatType)1 LinearIntensityMap (org.janelia.intensity.LinearIntensityMap)1