Search in sources :

Example 31 with ShortProcessor

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

the class ImageArrayConverter method ImageToFloatArray2DDeprecated.

public static float[][] ImageToFloatArray2DDeprecated(ImageProcessor ip) {
    float[][] image;
    Object pixelArray = ip.getPixels();
    int count = 0;
    if (ip instanceof ByteProcessor) {
        image = new float[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 float[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 float[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] = pixels[count++];
    } else // RGB
    {
        image = new float[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 32 with ShortProcessor

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

the class ImageArrayConverter method ImageToFloatArray2D.

public static FloatArray2D ImageToFloatArray2D(ImageProcessor ip) {
    FloatArray2D image;
    Object pixelArray = ip.getPixels();
    int count = 0;
    if (ip instanceof ByteProcessor) {
        image = new FloatArray2D(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.data[count] = pixels[count++] & 0xff;
    } else if (ip instanceof ShortProcessor) {
        image = new FloatArray2D(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.data[count] = pixels[count++] & 0xffff;
    } else if (ip instanceof FloatProcessor) {
        image = new FloatArray2D(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.data[count] = pixels[count++];
    } else // RGB
    {
        image = new FloatArray2D(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) FloatArray2D(mpi.fruitfly.math.datastructures.FloatArray2D) FloatProcessor(ij.process.FloatProcessor) Point(java.awt.Point) ShortProcessor(ij.process.ShortProcessor)

Example 33 with ShortProcessor

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

the class SplitResults method splitResults.

private void splitResults(MemoryPeakResults results, ImageProcessor ip) {
    IJ.showStatus("Splitting " + TextUtils.pleural(results.size(), "result"));
    // Create an object mask
    final ObjectAnalyzer objectAnalyzer = new ObjectAnalyzer(ip, false);
    final int maxx = ip.getWidth();
    final int maxy = ip.getHeight();
    final Rectangle bounds = results.getBounds();
    final double ox = bounds.getX();
    final double oy = bounds.getY();
    final double scaleX = bounds.getWidth() / maxx;
    final double scaleY = bounds.getHeight() / maxy;
    // Create a results set for each object
    final int maxObject = objectAnalyzer.getMaxObject();
    final MemoryPeakResults[] resultsSet = new MemoryPeakResults[maxObject + 1];
    for (int object = 0; object <= maxObject; object++) {
        final MemoryPeakResults newResults = new MemoryPeakResults();
        newResults.copySettings(results);
        newResults.setName(results.getName() + " " + object);
        resultsSet[object] = newResults;
    }
    final int[] mask = objectAnalyzer.getObjectMask();
    if (settings.showObjectMask) {
        final ImageProcessor objectIp = (maxObject <= 255) ? new ByteProcessor(maxx, maxy) : new ShortProcessor(maxx, maxy);
        for (int i = 0; i < mask.length; i++) {
            objectIp.set(i, mask[i]);
        }
        final ImagePlus imp = ImageJUtils.display(settings.objectMask + " Objects", objectIp);
        imp.setDisplayRange(0, maxObject);
        imp.updateAndDraw();
    }
    // Process the results mapping them to their objects
    final Counter i = new Counter();
    final int size = results.size();
    final int step = ImageJUtils.getProgressInterval(size);
    results.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
        if (i.incrementAndGet() % step == 0) {
            IJ.showProgress(i.getCount(), size);
        }
        // Map to the mask objects
        final int object;
        final int x = (int) ((xx - ox) / scaleX);
        final int y = (int) ((yy - oy) / scaleY);
        if (x < 0 || x >= maxx || y < 0 || y >= maxy) {
            object = 0;
        } else {
            final int index = y * maxx + x;
            // is within the bounds of the image processor?
            if (index < 0 || index >= mask.length) {
                object = 0;
            } else {
                object = mask[index];
            }
        }
        resultsSet[object].add(result);
    });
    IJ.showProgress(1);
    // Add the new results sets to memory
    i.reset();
    for (int object = (settings.nonMaskDataset) ? 0 : 1; object <= maxObject; object++) {
        if (resultsSet[object].isNotEmpty()) {
            MemoryPeakResults.addResults(resultsSet[object]);
            i.increment();
        }
    }
    IJ.showStatus("Split " + TextUtils.pleural(results.size(), "result") + " into " + TextUtils.pleural(i.getCount(), "set"));
}
Also used : ByteProcessor(ij.process.ByteProcessor) Rectangle(java.awt.Rectangle) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ByteProcessor(ij.process.ByteProcessor) ObjectAnalyzer(uk.ac.sussex.gdsc.smlm.ij.utils.ObjectAnalyzer) ImageProcessor(ij.process.ImageProcessor) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) WindowManager(ij.WindowManager) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) AtomicReference(java.util.concurrent.atomic.AtomicReference) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) ImagePlus(ij.ImagePlus) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) ShortProcessor(ij.process.ShortProcessor) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) IJ(ij.IJ) PlugIn(ij.plugin.PlugIn) Rectangle(java.awt.Rectangle) ImagePlus(ij.ImagePlus) ShortProcessor(ij.process.ShortProcessor) ImageProcessor(ij.process.ImageProcessor) ObjectAnalyzer(uk.ac.sussex.gdsc.smlm.ij.utils.ObjectAnalyzer) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)

Example 34 with ShortProcessor

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

the class ImageJImagePeakResults method createNewProcessor.

private ImageProcessor createNewProcessor(int imageWidth, int imageHeight) {
    // Equalised display requires a 16-bit image to allow fast processing of the histogram
    if ((displayFlags & DISPLAY_EQUALIZED) != 0) {
        pixels = new short[data.length];
        return new ShortProcessor(imageWidth, imageHeight, (short[]) pixels, null);
    }
    pixels = new float[data.length];
    // Zero is mapped to 0 in the LUT.
    if ((displayFlags & DISPLAY_MAPPED) != 0) {
        final MappedFloatProcessor fp = new MappedFloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
        fp.setMapZero((displayFlags & DISPLAY_MAP_ZERO) != 0);
        return fp;
    }
    // -Infinity is mapped to 0 in the LUT.
    if ((displayFlags & DISPLAY_NEGATIVES) != 0) {
        return new InfinityMappedFloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
    }
    return new FloatProcessor(imageWidth, imageHeight, (float[]) pixels, null);
}
Also used : InfinityMappedFloatProcessor(uk.ac.sussex.gdsc.core.ij.process.InfinityMappedFloatProcessor) MappedFloatProcessor(uk.ac.sussex.gdsc.core.ij.process.MappedFloatProcessor) FloatProcessor(ij.process.FloatProcessor) InfinityMappedFloatProcessor(uk.ac.sussex.gdsc.core.ij.process.InfinityMappedFloatProcessor) InfinityMappedFloatProcessor(uk.ac.sussex.gdsc.core.ij.process.InfinityMappedFloatProcessor) MappedFloatProcessor(uk.ac.sussex.gdsc.core.ij.process.MappedFloatProcessor) 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