Search in sources :

Example 6 with FloatArray2D

use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.

the class ImageArrayConverter method drawTranslatedImages.

public static FloatArray2D drawTranslatedImages(FloatArray2D img1, FloatArray2D img2, Point shift, int drawType) {
    int w1 = img1.width;
    int h1 = img1.height;
    int w2 = img2.width;
    int h2 = img2.height;
    boolean createOverlappingImages = (drawType == DRAWTYPE_OVERLAP);
    boolean createErrorMap = (drawType == DRAWTYPE_ERRORMAP);
    int sx = shift.x;
    int sy = shift.y;
    int imgW = max(w1, w2) + max(0, Math.abs(sx) - Math.abs((w1 - w2)));
    int imgH = max(h1, h2) + max(0, Math.abs(sy) - Math.abs((h1 - h2)));
    FloatArray2D outputImg = new FloatArray2D(imgW, imgH);
    // + max(0, max(0, -sx) - max(0, (w1 - w2)/2));
    int offsetImg1X = max(0, -sx);
    // + max(0, max(0, -sy) - max(0, (h1 - h2)/2));
    int offsetImg1Y = max(0, -sy);
    // + max(0, max(0, sx) - max(0, (w2 - w1)/2));
    int offsetImg2X = max(0, sx);
    // + max(0, max(0, sy) - max(0, (h2 - h1)/2));
    int offsetImg2Y = max(0, sy);
    float pixel1, pixel2;
    // iterate over whole image
    for (int y = 0; y < imgH; y++) for (int x = 0; x < imgW; x++) {
        pixel1 = img1.getZero(x - offsetImg1X, y - offsetImg1Y);
        pixel2 = img2.getZero(x - offsetImg2X, y - offsetImg2Y);
        if (createOverlappingImages)
            outputImg.set((pixel1 + pixel2) / 2f, x, y);
        // compute errors only if the images overlap
        if (x >= offsetImg1X && x >= offsetImg2X && x < offsetImg1X + w1 && x < offsetImg2X + w2 && y >= offsetImg1Y && y >= offsetImg2Y && y < offsetImg1Y + h1 && y < offsetImg2Y + h2) {
            if (createErrorMap)
                outputImg.set((pixel1 + pixel2) / 2f, x, y);
        }
    }
    return outputImg;
}
Also used : FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) Point(java.awt.Point)

Example 7 with FloatArray2D

use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.

the class ImageArrayConverter method ImageToFloatArray2DZeroPadding.

public static FloatArray2D ImageToFloatArray2DZeroPadding(ImageProcessor ip, int width, int height) {
    FloatArray2D image = new FloatArray2D(width, height);
    Object pixelArray = ip.getPixels();
    int count = 0;
    int offsetX = (width - ip.getWidth()) / 2;
    int offsetY = (height - ip.getHeight()) / 2;
    if (offsetX < 0) {
        System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToFloatArray2DZeroPadding(): Zero-Padding size in X smaller than image! " + width + " < " + ip.getWidth());
        return null;
    }
    if (offsetY < 0) {
        System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToFloatArray2DZeroPadding(): Zero-Padding size in Y smaller than image! " + height + " < " + ip.getHeight());
        return null;
    }
    if (ip instanceof ByteProcessor) {
        byte[] pixels = (byte[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++] & 0xff, x + offsetX, y + offsetY);
    } else if (ip instanceof ShortProcessor) {
        short[] pixels = (short[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++] & 0xffff, x + offsetX, y + offsetY);
    } else if (ip instanceof FloatProcessor) {
        float[] pixels = (float[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image.set(pixels[count++], x + offsetX, y + offsetY);
    } else // RGB
    {
        int[] pixels = (int[]) pixelArray;
    // still unknown how to do...
    /*
            for (int y = 0; y < ip.getHeight(); y++)
                for (int x = 0; x < ip.getWidth(); x++)
                        image[x][y] = pixels[count++];// & 0xffffff;
            */
    }
    return image;
}
Also used : ByteProcessor(ij.process.ByteProcessor) FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) FloatProcessor(ij.process.FloatProcessor) Point(java.awt.Point) ShortProcessor(ij.process.ShortProcessor)

Example 8 with FloatArray2D

use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.

the class ImageArrayConverter method zeroPad.

public static FloatArray2D zeroPad(FloatArray2D ip, int width, int height) {
    FloatArray2D image = new FloatArray2D(width, height);
    int offsetX = (width - ip.width) / 2;
    int offsetY = (height - ip.height) / 2;
    if (offsetX < 0) {
        System.err.println("mpi.fruitfly.general.ImageArrayConverter.ZeroPad(): Zero-Padding size in X smaller than image! " + width + " < " + ip.width);
        return null;
    }
    if (offsetY < 0) {
        System.err.println("mpi.fruitfly.general.ImageArrayConverter.ZeroPad(): Zero-Padding size in Y smaller than image! " + height + " < " + ip.height);
        return null;
    }
    int count = 0;
    for (int y = 0; y < ip.height; y++) for (int x = 0; x < ip.width; x++) image.set(ip.data[count++], x + offsetX, y + offsetY);
    return image;
}
Also used : FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) Point(java.awt.Point)

Example 9 with FloatArray2D

use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.

the class Loader method scaleImage.

public static ImageProcessor scaleImage(final ImagePlus imp, final int level, final boolean quality) {
    if (level <= 0)
        return imp.getProcessor();
    // else, make a properly scaled image:
    // - gaussian blurred for best quality when resizing with nearest neighbor
    // - direct nearest neighbor otherwise
    ImageProcessor ip = imp.getProcessor();
    final int w = ip.getWidth();
    final int h = ip.getHeight();
    final double mag = 1 / Math.pow(2, level);
    // TODO releseToFit !
    if (quality) {
        // apply proper gaussian filter
        // sigma = sqrt(level^2 - 0.5^2)
        final double sigma = Math.sqrt(Math.pow(2, level) - 0.25);
        ip = new FloatProcessorT2(w, h, ImageFilter.computeGaussianFastMirror(new FloatArray2D((float[]) ip.convertToFloat().getPixels(), w, h), (float) sigma).data, ip.getDefaultColorModel(), ip.getMin(), ip.getMax());
        // better while float
        ip = ip.resize((int) (w * mag), (int) (h * mag));
        return Utils.convertTo(ip, imp.getType(), false);
    } else {
        return ip.resize((int) (w * mag), (int) (h * mag));
    }
}
Also used : ImageProcessor(ij.process.ImageProcessor) FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) FloatProcessorT2(ini.trakem2.imaging.FloatProcessorT2)

Example 10 with FloatArray2D

use of mpi.fruitfly.math.datastructures.FloatArray2D in project TrakEM2 by trakem2.

the class Loader method scaleImage.

public static ImageProcessor scaleImage(final ImagePlus imp, double mag, final boolean quality) {
    if (mag > 1)
        mag = 1;
    ImageProcessor ip = imp.getProcessor();
    if (Math.abs(mag - 1) < 0.000001)
        return ip;
    // else, make a properly scaled image:
    // - gaussian blurred for best quality when resizing with nearest neighbor
    // - direct nearest neighbor otherwise
    final int w = ip.getWidth();
    final int h = ip.getHeight();
    // TODO releseToFit !
    if (quality) {
        // apply proper gaussian filter
        // sigma = sqrt(level^2 - 0.5^2)
        final double sigma = Math.sqrt(Math.pow(2, getMipMapLevel(mag, Math.max(imp.getWidth(), imp.getHeight()))) - 0.25);
        ip = new FloatProcessorT2(w, h, ImageFilter.computeGaussianFastMirror(new FloatArray2D((float[]) ip.convertToFloat().getPixels(), w, h), (float) sigma).data, ip.getDefaultColorModel(), ip.getMin(), ip.getMax());
        // better while float
        ip = ip.resize((int) (w * mag), (int) (h * mag));
        return Utils.convertTo(ip, imp.getType(), false);
    } else {
        return ip.resize((int) (w * mag), (int) (h * mag));
    }
}
Also used : ImageProcessor(ij.process.ImageProcessor) FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) FloatProcessorT2(ini.trakem2.imaging.FloatProcessorT2)

Aggregations

FloatArray2D (mpi.fruitfly.math.datastructures.FloatArray2D)21 Point (java.awt.Point)6 ImageProcessor (ij.process.ImageProcessor)4 ImagePlus (ij.ImagePlus)2 Roi (ij.gui.Roi)2 ByteProcessor (ij.process.ByteProcessor)2 FloatProcessor (ij.process.FloatProcessor)2 ShortProcessor (ij.process.ShortProcessor)2 FloatProcessorT2 (ini.trakem2.imaging.FloatProcessorT2)2 Rectangle (java.awt.Rectangle)2 Random (java.util.Random)2 ImageToFloatArray2D (mpi.fruitfly.general.ImageArrayConverter.ImageToFloatArray2D)2 Patch (ini.trakem2.display.Patch)1 Loader (ini.trakem2.persistence.Loader)1 Image (java.awt.Image)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CrossCorrelation2D (mpi.fruitfly.registration.CrossCorrelation2D)1 PhaseCorrelationPeak (mpicbg.imglib.algorithm.fft.PhaseCorrelationPeak)1 Point (mpicbg.models.Point)1