Search in sources :

Example 1 with LocalList

use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.

the class BenchmarkSpotFilter method runFilter.

private BatchResult[] runFilter(DataFilterMethod dataFilter, double[] param, int search, double param2) {
    // Set the prefix for this batch
    final double hwhmMin = config.getHwhmMin();
    progressPrefix = new BatchResult(null, dataFilter, 0, search, param2, hwhmMin).getName();
    final LocalList<BatchResult> result = new LocalList<>();
    // For difference filters
    if (param2 > 0) {
        // Note: Add a dummy first param so we can set the second param
        config.setDataFilter(dataFilter, param2, true, 0);
        config.setDataFilter(dataFilter, param2, true, 1);
    }
    for (int i = 0; i < param.length; i++) {
        config.setDataFilter(dataFilter, param[i], true, 0);
        try {
            final BenchmarkSpotFilterResult localFilterResult = runAnalysis(config, false);
            if (localFilterResult != null) {
                result.add(new BatchResult(localFilterResult, dataFilter, param[i], search, param2, hwhmMin));
            }
        } catch (final IllegalArgumentException ex) {
            // This can occur during batch processing when the param2 argument is smaller than param
            break;
        }
    }
    return result.toArray(new BatchResult[0]);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Example 2 with LocalList

use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.

the class CreateData method loadBenchmarkData.

/**
 * Load benchmark data using an open image and a XYZ text file.
 */
private void loadBenchmarkData() {
    if (!showLoadDialog()) {
        // resetMemory();
        return;
    }
    // Load the image
    final ImagePlus imp = WindowManager.getImage(benchmarkImage);
    if (imp == null) {
        IJ.error(TITLE, "No benchmark image: " + benchmarkImage);
        // resetMemory();
        return;
    }
    // Load the results
    final MemoryPeakResults results = getSimulationResults();
    if (results == null) {
        IJ.error(TITLE, "No benchmark results: " + benchmarkResultsName);
        // resetMemory();
        return;
    }
    results.setName(imp.getTitle() + " (Results)");
    results.setBounds(new Rectangle(0, 0, imp.getWidth(), imp.getHeight()));
    final IJImageSource imageSource = new IJImageSource(imp);
    results.setSource(imageSource);
    // Load the settings as these are used in the dialog
    settings = SettingsManager.readCreateDataSettings(0).toBuilder();
    simulationParameters = showSimulationParametersDialog(imp, results);
    if (simulationParameters != null) {
        // Convert data to allow analysis as if a Gaussian2D PSF
        final boolean isGaussian2D = PsfHelper.isGaussian2D(results.getPsf());
        if (isGaussian2D) {
            Gaussian2DPeakResultHelper.addMeanIntensity(results.getPsf(), results);
        } else if (simulationParameters.sd > 0) {
            final TypeConverter<DistanceUnit> dc = results.getDistanceConverter(DistanceUnit.NM);
            final PSF.Builder psf = PsfProtosHelper.getDefaultPsf(PSFType.ONE_AXIS_GAUSSIAN_2D).toBuilder();
            psf.getParametersBuilder(0).setValue(dc.convertBack(simulationParameters.sd));
            results.setPsf(psf.build());
            // Update all the results. This assumes the results do not have data for a custom PSF,
            // i.e. the parameters only have [t,i,x,y,z]
            final LocalList<PeakResult> newResults = new LocalList<>(results.size());
            final float sd = (float) dc.convertBack(simulationParameters.sd);
            final double meanFactor = Gaussian2DPeakResultHelper.getMeanSignalUsingP05(1, sd, sd);
            results.forEach((PeakResultProcedure) r -> {
                final PeakResult peak = r.resize(PeakResult.STANDARD_PARAMETERS + 1);
                peak.setMeanIntensity((float) (peak.getIntensity() * meanFactor));
                peak.setParameter(PeakResult.STANDARD_PARAMETERS, sd);
                newResults.add(peak);
            });
            results.begin();
            results.addAll(newResults);
            results.end();
        }
        setBackground(results);
        setNoise(results, imp);
        setBenchmarkResults(imp, results);
        IJ.showStatus("Loaded " + TextUtils.pleural(results.size(), "result"));
    } else {
        resetMemory();
    }
}
Also used : TypeConverter(uk.ac.sussex.gdsc.core.data.utils.TypeConverter) IJImageSource(uk.ac.sussex.gdsc.smlm.ij.IJImageSource) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) HistogramPlotBuilder(uk.ac.sussex.gdsc.core.ij.HistogramPlot.HistogramPlotBuilder) AtomOrBuilder(uk.ac.sussex.gdsc.smlm.data.config.MoleculeProtos.AtomOrBuilder) Rectangle(java.awt.Rectangle) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) ImmutableMemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.ImmutableMemoryPeakResults) ImagePlus(ij.ImagePlus) IdPeakResult(uk.ac.sussex.gdsc.smlm.results.IdPeakResult) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) ExtendedPeakResult(uk.ac.sussex.gdsc.smlm.results.ExtendedPeakResult)

Example 3 with LocalList

use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.

the class CreateData method addPsfOptions.

/**
 * Check if there are any suitable PSF images open. If so add a choice to allow the selection of
 * the Gaussian or Image PSF model. If no PSF images are open then add options for the wavelength
 * and NA for the simulated microscope.
 *
 * @param gd the gd
 */
private void addPsfOptions(final ExtendedGenericDialog gd) {
    gd.addMessage("--- PSF Model ---");
    final List<String> imageNames = PsfCombiner.createImageList();
    final LocalList<String> availableModels = new LocalList<>();
    availableModels.add(PSF_MODELS[PSF_MODEL_GAUSSIAN]);
    availableModels.add(PSF_MODELS[PSF_MODEL_AIRY]);
    final String[] images;
    if (!imageNames.isEmpty()) {
        availableModels.add(PSF_MODELS[PSF_MODEL_IMAGE]);
        images = imageNames.toArray(new String[0]);
    } else {
        images = null;
    }
    final String[] astigmatismModels = AstigmatismModelManager.listAstigmatismModels(false, true);
    if (astigmatismModels.length != 0) {
        availableModels.add(PSF_MODELS[PSF_MODEL_ASTIGMATISM]);
    }
    final String[] models = availableModels.toArray(new String[0]);
    gd.addChoice("PSF_model", models, settings.getPsfModel(), new OptionListener<Integer>() {

        @Override
        public boolean collectOptions(Integer value) {
            settings.setPsfModel(models[value]);
            return collectOptions(false);
        }

        @Override
        public boolean collectOptions() {
            return collectOptions(true);
        }

        private boolean collectOptions(boolean silent) {
            final ExtendedGenericDialog egd = new ExtendedGenericDialog(TITLE, null);
            egd.addMessage("Configure the " + settings.getPsfModel() + " PSF model");
            int type = 0;
            // Get the image
            if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_IMAGE])) {
                egd.addChoice("PSF_image", images, settings.getPsfImageName());
            } else if (settings.getPsfModel().equals(PSF_MODELS[PSF_MODEL_ASTIGMATISM])) {
                type = 1;
                egd.addChoice("Astigmatism_model", astigmatismModels, settings.getAstigmatismModel());
                egd.addMessage(TextUtils.wrap("Note: The pixel size of the astigmatism model should match" + " the pixel pitch if fitting of the data is to be performed (i.e. fitting requires" + " the astigmatism model to be calibrated to the image). If not then the model will" + " be optionally converted before the simulation.", 80));
            } else {
                // Get the width of the model
                type = 2;
                egd.addNumericField("Depth-of-focus (nm)", settings.getDepthOfFocus(), 2);
                egd.addCheckbox("Enter_width", settings.getEnterWidth());
                egd.addNumericField("PSF_SD (nm)", settings.getPsfSd(), 2);
                egd.addMessage("Or compute from optics:");
                egd.addNumericField("Wavelength (nm)", settings.getWavelength(), 2);
                egd.addNumericField("Numerical_aperture", settings.getNumericalAperture(), 2);
            }
            egd.setSilent(silent);
            egd.showDialog(true, gd);
            if (egd.wasCanceled()) {
                return false;
            }
            if (type == 0) {
                settings.setPsfImageName(egd.getNextChoice());
            } else if (type == 1) {
                settings.setAstigmatismModel(AstigmatismModelManager.removeFormatting(egd.getNextChoice()));
            } else {
                settings.setDepthOfFocus(egd.getNextNumber());
                settings.setEnterWidth(egd.getNextBoolean());
                settings.setPsfSd(Math.abs(egd.getNextNumber()));
                settings.setWavelength(Math.abs(egd.getNextNumber()));
                settings.setNumericalAperture(Math.abs(egd.getNextNumber()));
            }
            return true;
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)

Example 4 with LocalList

use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.

the class Shape3DHelper method createDiscEdge.

/**
 * Creates the disc. This is copied from MeshMaker but the duplication of the vertices for both
 * sides on the disc is removed.
 *
 * @param x the x
 * @param y the y
 * @param z the z
 * @param nx the nx
 * @param ny the ny
 * @param nz the nz
 * @param radius the radius
 * @param edgePoints the edge points
 * @return the list
 */
private static List<Point3f> createDiscEdge(boolean includeCenter, final double x, final double y, final double z, final double nx, final double ny, final double nz, final double radius, final int edgePoints) {
    double ax;
    double ay;
    double az;
    if (Math.abs(nx) >= Math.abs(ny)) {
        final double scale = 1 / Math.sqrt(nx * nx + nz * nz);
        ax = -nz * scale;
        ay = 0;
        az = nx * scale;
    } else {
        final double scale = 1 / Math.sqrt(ny * ny + nz * nz);
        ax = 0;
        ay = nz * scale;
        az = -ny * scale;
    }
    /*
     * Now to find the other vector in that plane, do the cross product of (ax,ay,az) with
     * (nx,ny,nz)
     */
    double bx = (ay * nz - az * ny);
    double by = (az * nx - ax * nz);
    double bz = (ax * ny - ay * nx);
    final double bScale = 1 / Math.sqrt(bx * bx + by * by + bz * bz);
    bx *= bScale;
    by *= bScale;
    bz *= bScale;
    final LocalList<Point3f> list = new LocalList<>();
    if (includeCenter) {
        list.add(new Point3f((float) x, (float) y, (float) z));
    }
    for (int i = edgePoints + 1; i-- > 0; ) {
        // For consistency with the rendering of the icosahedron
        // we rotate by a quarter turn. The icosahedron projected
        // flat then looks like the hexagon.
        final double angle = Math.PI / 2 + (i * 2 * Math.PI) / edgePoints;
        final double c = Math.cos(angle);
        final double s = Math.sin(angle);
        final float px = (float) (x + radius * c * ax + radius * s * bx);
        final float py = (float) (y + radius * c * ay + radius * s * by);
        final float pz = (float) (z + radius * c * az + radius * s * bz);
        list.add(new Point3f(px, py, pz));
    }
    return list;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Point3f(org.scijava.vecmath.Point3f)

Example 5 with LocalList

use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.

the class Shape3DHelper method createIndexedObject.

/**
 * Creates an indexed object from a list of vertices.
 *
 * @param list the list of vertices
 * @return the vertices and indices of the the object
 */
public static Pair<Point3f[], int[]> createIndexedObject(List<Point3f> list) {
    // Compact the vertices to a set of vertices and faces
    final TObjectIntHashMap<Point3f> m = new TObjectIntHashMap<>(list.size(), 0.5f, -1);
    final LocalList<Point3f> vertices = new LocalList<>(list.size());
    final TIntArrayList faces = new TIntArrayList(list.size());
    int index = 0;
    // Process triangles
    for (int i = 0; i < list.size(); i++) {
        final Point3f p = list.get(i);
        int value = m.putIfAbsent(p, index);
        if (value == -1) {
            // Store the points in order
            vertices.add(p);
            value = index++;
        }
        faces.add(value);
    }
    return Pair.of(vertices.toArray(new Point3f[0]), faces.toArray());
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Point3f(org.scijava.vecmath.Point3f) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)70 PeakResult (uk.ac.sussex.gdsc.smlm.results.PeakResult)19 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)15 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)14 ImagePlus (ij.ImagePlus)13 Point (java.awt.Point)13 Future (java.util.concurrent.Future)13 Plot (ij.gui.Plot)11 ExecutorService (java.util.concurrent.ExecutorService)11 WindowOrganiser (uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser)11 TIntArrayList (gnu.trove.list.array.TIntArrayList)10 IJ (ij.IJ)10 PlugIn (ij.plugin.PlugIn)10 Rectangle (java.awt.Rectangle)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)10 DistanceUnit (uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit)10 Color (java.awt.Color)9 Arrays (java.util.Arrays)9 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9