Search in sources :

Example 11 with ShortProcessor

use of ij.process.ShortProcessor in project TrakEM2 by trakem2.

the class ImageArrayConverter method ImageToDoubleArray1DZeroPadding.

public static double[] ImageToDoubleArray1DZeroPadding(ImageProcessor ip, int width, int height) {
    double[] image;
    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.ImageToDoubleArray1DZeroPadding(): Zero-Padding size in X smaller than image! " + width + " < " + ip.getWidth());
        return null;
    }
    if (offsetY < 0) {
        System.err.println("mpi.fruitfly.general.ImageArrayConverter.ImageToDoubleArray1DZeroPadding(): Zero-Padding size in Y smaller than image! " + height + " < " + ip.getHeight());
        return null;
    }
    if (ip instanceof ByteProcessor) {
        image = new double[width * height];
        byte[] pixels = (byte[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++] & 0xff;
    } else if (ip instanceof ShortProcessor) {
        image = new double[width * height];
        short[] pixels = (short[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++] & 0xffff;
    } else if (ip instanceof FloatProcessor) {
        image = new double[width * height];
        float[] pixels = (float[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[(y + offsetY) * width + x + offsetX] = pixels[count++];
    } else // RGB
    {
        image = new double[width * height];
        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) FloatProcessor(ij.process.FloatProcessor) Point(java.awt.Point) ShortProcessor(ij.process.ShortProcessor)

Example 12 with ShortProcessor

use of ij.process.ShortProcessor in project TrakEM2 by trakem2.

the class ImageArrayConverter method ImageToIntArray.

public static int[][] ImageToIntArray(ImageProcessor ip) {
    int[][] image;
    Object pixelArray = ip.getPixels();
    int count = 0;
    if (ip instanceof ByteProcessor) {
        image = new int[ip.getWidth()][ip.getHeight()];
        byte[] pixels = (byte[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = pixels[count++] & 0xff;
    } else if (ip instanceof ShortProcessor) {
        image = new int[ip.getWidth()][ip.getHeight()];
        short[] pixels = (short[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = pixels[count++] & 0xffff;
    } else if (ip instanceof FloatProcessor) {
        image = new int[ip.getWidth()][ip.getHeight()];
        float[] pixels = (float[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[x][y] = (int) pixels[count++];
    } else // RGB
    {
        image = new int[ip.getWidth()][ip.getHeight()];
        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) FloatProcessor(ij.process.FloatProcessor) Point(java.awt.Point) ShortProcessor(ij.process.ShortProcessor)

Example 13 with ShortProcessor

use of ij.process.ShortProcessor 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 14 with ShortProcessor

use of ij.process.ShortProcessor in project TrakEM2 by trakem2.

the class ImageArrayConverter method ImageToDoubleArray1D.

public static double[] ImageToDoubleArray1D(ImageProcessor ip) {
    double[] image;
    Object pixelArray = ip.getPixels();
    int count = 0;
    if (ip instanceof ByteProcessor) {
        image = new double[ip.getWidth() * ip.getHeight()];
        byte[] pixels = (byte[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++] & 0xff;
    } else if (ip instanceof ShortProcessor) {
        image = new double[ip.getWidth() * ip.getHeight()];
        short[] pixels = (short[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++] & 0xffff;
    } else if (ip instanceof FloatProcessor) {
        image = new double[ip.getWidth() * ip.getHeight()];
        float[] pixels = (float[]) pixelArray;
        for (int y = 0; y < ip.getHeight(); y++) for (int x = 0; x < ip.getWidth(); x++) image[count] = pixels[count++];
    } else // RGB
    {
        image = new double[ip.getWidth() * ip.getHeight()];
        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) FloatProcessor(ij.process.FloatProcessor) Point(java.awt.Point) ShortProcessor(ij.process.ShortProcessor)

Example 15 with ShortProcessor

use of ij.process.ShortProcessor in project GDSC-SMLM by aherbert.

the class CreateData method updateArea.

private void updateArea(int[] mask, int width, int height) {
    // Note: The apparent area will be bigger due to the PSF width blurring the edges.
    // Assume the entire max intensity mask is in focus and the PSF is Gaussian in the focal plane.
    // Blur the mask
    final float[] pixels = new float[mask.length];
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = mask[i];
    }
    final GaussianFilter blur = new GaussianFilter();
    final double scaleX = (double) settings.getSize() / width;
    final double scaleY = (double) settings.getSize() / height;
    // Allow extra?
    final double extra = 1;
    final double sd = getPsfSd() * extra;
    blur.convolve(pixels, width, height, sd / scaleX, sd / scaleY);
    // Count pixels in blurred mask. Ignore those that are very faint (at the edge of the region)
    int count = 0;
    // // By fraction of max value
    // float limit = 0.1f;
    // //float min = (float) (Maths.max(pixels) * limit);
    // float min = limit;
    // for (float f : pixels)
    // if (f > min)
    // c++;
    // // Rank in order and get fraction of sum
    // Arrays.sort(pixels);
    // double sum = 0;
    // double stop = Maths.sum(pixels) * 0.95;
    // float after = Maths.max(pixels) + 1;
    // for (float f : pixels)
    // {
    // sum += f;
    // if (sum > stop)
    // {
    // break;
    // //after = f;
    // //stop = Float.POSITIVE_INFINITY;
    // }
    // if (f > after)
    // break;
    // c++;
    // }
    // Threshold to a mask
    final FloatProcessor fp = new FloatProcessor(width, height, pixels);
    final ShortProcessor sp = (ShortProcessor) fp.convertToShort(true);
    final int t = AutoThreshold.getThreshold(AutoThreshold.Method.OTSU, sp.getHistogram());
    // Utils.display("Blurred", fp);
    for (int i = 0; i < mask.length; i++) {
        if (sp.get(i) >= t) {
            count++;
        }
    }
    // Convert
    final double scale = ((double) count) / mask.length;
    // System.out.printf("Scale = %f\n", scale);
    areaInUm = scale * settings.getSize() * settings.getPixelPitch() * settings.getSize() * settings.getPixelPitch() / 1e6;
}
Also used : GaussianFilter(uk.ac.sussex.gdsc.smlm.filters.GaussianFilter) FloatProcessor(ij.process.FloatProcessor) ReadHint(uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint) ShortProcessor(ij.process.ShortProcessor)

Aggregations

ShortProcessor (ij.process.ShortProcessor)34 FloatProcessor (ij.process.FloatProcessor)20 ByteProcessor (ij.process.ByteProcessor)19 ImageProcessor (ij.process.ImageProcessor)10 ImagePlus (ij.ImagePlus)8 Point (java.awt.Point)8 Rectangle (java.awt.Rectangle)6 ArrayList (java.util.ArrayList)6 ImageStack (ij.ImageStack)4 ColorProcessor (ij.process.ColorProcessor)4 LUT (ij.process.LUT)3 Displayable (ini.trakem2.display.Displayable)3 Patch (ini.trakem2.display.Patch)3 FormatException (loci.formats.FormatException)3 ImageJ (ij.ImageJ)2 GenericDialog (ij.gui.GenericDialog)2 Calibration (ij.measure.Calibration)2 AffineTransform (java.awt.geom.AffineTransform)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2