Search in sources :

Example 6 with ByteProcessor

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

the class DiffusionRateTest method showExample.

private void showExample(int totalSteps, double diffusionSigma, RandomGenerator[] random) {
    MoleculeModel m = new MoleculeModel(0, new double[3]);
    float[] xValues = new float[totalSteps];
    float[] x = new float[totalSteps];
    float[] y = new float[totalSteps];
    final double[] axis = (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) ? nextVector() : null;
    for (int j = 0; j < totalSteps; j++) {
        if (settings.getDiffusionType() == DiffusionType.GRID_WALK)
            m.walk(diffusionSigma, random);
        else if (settings.getDiffusionType() == DiffusionType.LINEAR_WALK)
            m.slide(diffusionSigma, axis, random[0]);
        else
            m.move(diffusionSigma, random);
        x[j] = (float) (m.getX());
        y[j] = (float) (m.getY());
        xValues[j] = (float) ((j + 1) / settings.stepsPerSecond);
    }
    // Plot x and y coords on a timeline
    String title = TITLE + " example coordinates";
    Plot2 plot = new Plot2(title, "Time (seconds)", "Distance (um)");
    float[] xUm = convertToUm(x);
    float[] yUm = convertToUm(y);
    float[] limits = Maths.limits(xUm);
    limits = Maths.limits(limits, yUm);
    plot.setLimits(0, totalSteps / settings.stepsPerSecond, limits[0], limits[1]);
    plot.setColor(Color.red);
    plot.addPoints(xValues, xUm, Plot2.LINE);
    plot.setColor(Color.blue);
    plot.addPoints(xValues, yUm, Plot2.LINE);
    Utils.display(title, plot);
    // Scale up and draw 2D position
    for (int j = 0; j < totalSteps; j++) {
        x[j] *= magnification;
        y[j] *= magnification;
    }
    float[] limitsx = getLimits(x);
    float[] limitsy = getLimits(y);
    int width = (int) (limitsx[1] - limitsx[0]);
    int height = (int) (limitsy[1] - limitsy[0]);
    // Ensure we draw something, even it is a simple dot at the centre for no diffusion
    if (width == 0) {
        width = (int) (32 * magnification);
        limitsx[0] = -width / 2;
    }
    if (height == 0) {
        height = (int) (32 * magnification);
        limitsy[0] = -height / 2;
    }
    ImageProcessor ip = new ByteProcessor(width, height);
    // Adjust x and y using the minimum to centre
    x[0] -= limitsx[0];
    y[0] -= limitsy[0];
    for (int j = 1; j < totalSteps; j++) {
        // Adjust x and y using the minimum to centre
        x[j] -= limitsx[0];
        y[j] -= limitsy[0];
        // Draw a line
        ip.setColor(32 + (223 * j) / (totalSteps - 1));
        ip.drawLine(round(x[j - 1]), round(y[j - 1]), round(x[j]), round(y[j]));
    }
    // Draw the final position
    ip.putPixel((int) round(x[totalSteps - 1]), (int) round(y[totalSteps - 1]), 255);
    ImagePlus imp = Utils.display(TITLE + " example", ip);
    // Apply the fire lookup table
    WindowManager.setTempCurrentImage(imp);
    LutLoader lut = new LutLoader();
    lut.run("fire");
    WindowManager.setTempCurrentImage(null);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) MoleculeModel(gdsc.smlm.model.MoleculeModel) LutLoader(ij.plugin.LutLoader) Plot2(ij.gui.Plot2) ImagePlus(ij.ImagePlus)

Example 7 with ByteProcessor

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

the class SplitResults method splitResults.

private void splitResults(MemoryPeakResults results, ImageProcessor ip) {
    IJ.showStatus("Splitting " + Utils.pleural(results.size(), "result"));
    // Create an object mask
    ObjectAnalyzer objectAnalyzer = new ObjectAnalyzer(ip, false);
    final int maxx = ip.getWidth();
    final int maxy = ip.getHeight();
    final float scaleX = (float) results.getBounds().width / maxx;
    final float scaleY = (float) results.getBounds().height / maxy;
    // Create a results set for each object
    final int maxObject = objectAnalyzer.getMaxObject();
    MemoryPeakResults[] resultsSet = new MemoryPeakResults[maxObject + 1];
    for (int object = 0; object <= maxObject; object++) {
        MemoryPeakResults newResults = new MemoryPeakResults();
        newResults.copySettings(results);
        newResults.setName(results.getName() + " " + object);
        resultsSet[object] = newResults;
    }
    final int[] mask = objectAnalyzer.getObjectMask();
    if (showObjectMask) {
        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]);
        ImagePlus imp = Utils.display(objectMask + " Objects", objectIp);
        imp.setDisplayRange(0, maxObject);
        imp.updateAndDraw();
    }
    // Process the results mapping them to their objects
    int i = 0;
    final int size = results.size();
    final int step = Utils.getProgressInterval(size);
    for (PeakResult result : results.getResults()) {
        if (++i % step == 0)
            IJ.showProgress(i, size);
        // Map to the mask objects
        final int object;
        int x = (int) (result.getXPosition() / scaleX);
        int y = (int) (result.getYPosition() / scaleY);
        if (x < 0 || x >= maxx || y < 0 || y >= maxy) {
            object = 0;
        } else {
            final int index = y * maxx + x;
            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 = 0;
    for (int object = (nonMaskDataset) ? 0 : 1; object <= maxObject; object++) {
        if (!resultsSet[object].isEmpty()) {
            MemoryPeakResults.addResults(resultsSet[object]);
            i++;
        }
    }
    IJ.showStatus("Split " + Utils.pleural(results.size(), "result") + " into " + Utils.pleural(i, "set"));
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) ObjectAnalyzer(gdsc.smlm.ij.utils.ObjectAnalyzer) MemoryPeakResults(gdsc.smlm.results.MemoryPeakResults) ImagePlus(ij.ImagePlus) PeakResult(gdsc.smlm.results.PeakResult) ShortProcessor(ij.process.ShortProcessor)

Example 8 with ByteProcessor

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

the class YeastMask method createMask.

private void createMask() {
    // Create the dimensions
    final int hw = (int) Math.ceil(radius * 1000 / nmPerPixel);
    final int hd = (int) Math.ceil(radius * 1000 / nmPerSlice);
    final int width = 2 * hw + 1;
    final int depth = 2 * hd + 1;
    ImageStack stack = createHemiSphere(width, depth);
    // Extend the centre circle of the sphere into a tube of the required length
    final int h = (int) Math.ceil(length * 1000 / nmPerPixel);
    if (h > 0) {
        ImageStack newStack = new ImageStack(width, stack.getHeight() + h, stack.getSize());
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            byte[] pixels = (byte[]) stack.getPixels(slice);
            byte[] newPixels = new byte[width * newStack.getHeight()];
            newStack.setPixels(newPixels, slice);
            System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
            // Get the final strip to be extended
            final int offset = pixels.length - width;
            int target = pixels.length;
            for (int i = 0; i < h; i++) {
                System.arraycopy(pixels, offset, newPixels, target, width);
                target += width;
            }
        }
        stack = newStack;
    }
    // Copy the hemi-sphere onto the end
    ImageStack newStack = new ImageStack(width, stack.getHeight() + hw, stack.getSize());
    for (int slice = 1; slice <= stack.getSize(); slice++) {
        byte[] pixels = (byte[]) stack.getPixels(slice);
        byte[] newPixels = new byte[width * newStack.getHeight()];
        newStack.setPixels(newPixels, slice);
        System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
        // Copy the hemi-sphere
        int source = 0;
        int target = newPixels.length - width;
        for (int i = 0; i < hw; i++) {
            System.arraycopy(pixels, source, newPixels, target, width);
            target -= width;
            source += width;
        }
    }
    stack = newStack;
    if (excludeNucleus) {
        ImageStack stack2 = createNucleusSphere(width, depth);
        int xloc = (stack.getWidth() - stack2.getWidth()) / 2;
        int yloc = (stack.getHeight() - stack2.getHeight()) / 2;
        int offset = (stack.getSize() - stack2.getSize()) / 2;
        for (int slice = 1; slice <= stack2.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice + offset);
            ImageProcessor ip2 = stack2.getProcessor(slice);
            ip.copyBits(ip2, xloc, yloc, Blitter.SUBTRACT);
        }
    }
    if (squareOutput && stack.getWidth() != stack.getHeight()) {
        ImageStack stack2 = new ImageStack(stack.getHeight(), stack.getHeight());
        int end = stack.getHeight() - stack.getWidth();
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice);
            ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
            stack2.addSlice(ip2);
            for (int xloc = 0; xloc <= end; xloc += stack.getWidth()) {
                ip2.insert(ip, xloc, 0);
            }
        }
        stack = stack2;
    }
    if (border > 0) {
        ImageStack stack2 = new ImageStack(stack.getWidth() + 2 * border, stack.getHeight() + 2 * border);
        for (int slice = 1; slice <= stack.getSize(); slice++) {
            ImageProcessor ip = stack.getProcessor(slice);
            ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
            stack2.addSlice(ip2);
            ip2.insert(ip, border, border);
        }
        stack = stack2;
    }
    ImagePlus imp;
    if (is2D) {
        // TODO - Remove this laziness since we should really just do a 2D image
        int centre = stack.getSize() / 2;
        imp = Utils.display(TITLE, stack.getProcessor(centre));
    } else {
        imp = Utils.display(TITLE, stack);
    }
    // Calibrate
    Calibration cal = new Calibration();
    cal.setUnit("um");
    cal.pixelWidth = cal.pixelHeight = nmPerPixel / 1000;
    cal.pixelDepth = nmPerSlice / 1000;
    imp.setCalibration(cal);
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) ImageStack(ij.ImageStack) Calibration(ij.measure.Calibration) ImagePlus(ij.ImagePlus)

Aggregations

ByteProcessor (ij.process.ByteProcessor)8 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)4 ImagePlus (ij.ImagePlus)4 PeakResult (gdsc.smlm.results.PeakResult)3 ImageProcessor (ij.process.ImageProcessor)3 ClusterPoint (gdsc.core.clustering.ClusterPoint)2 MaskDistribution (gdsc.smlm.model.MaskDistribution)2 ImageStack (ij.ImageStack)2 Plot2 (ij.gui.Plot2)2 ShortProcessor (ij.process.ShortProcessor)2 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)2 BasePoint (gdsc.core.match.BasePoint)1 Statistics (gdsc.core.utils.Statistics)1 StoredData (gdsc.core.utils.StoredData)1 StoredDataStatistics (gdsc.core.utils.StoredDataStatistics)1 ObjectAnalyzer (gdsc.smlm.ij.utils.ObjectAnalyzer)1 MoleculeModel (gdsc.smlm.model.MoleculeModel)1 UniformDistribution (gdsc.smlm.model.UniformDistribution)1 NullSource (gdsc.smlm.results.NullSource)1 Trace (gdsc.smlm.results.Trace)1