Search in sources :

Example 66 with LocalList

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

the class PsfCreator method extractPsfs.

private ExtractedPsf[] extractPsfs(final float[][] image, final BasePoint[] centres) {
    final List<Future<?>> futures = new LocalList<>(centres.length);
    final int w = imp.getWidth();
    final int h = imp.getHeight();
    final ExtractedPsf[] psfs = new ExtractedPsf[centres.length];
    for (int i = 0; i < centres.length; i++) {
        final int index = i;
        futures.add(threadPool.submit(() -> {
            psfs[index] = new ExtractedPsf(image, w, h, centres[index], boxRadius, zRadius, settings.getAlignmentMagnification());
            // Do this here within the thread
            psfs[index].createProjections();
        // psfs[index].show(TITLE + index);
        }));
    }
    ConcurrencyUtils.waitForCompletionUnchecked(futures);
    return psfs;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Future(java.util.concurrent.Future) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Example 67 with LocalList

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

the class PsfCreator method align2.

/**
 * Align the PSFs with the combined PSF using the uk.ac.sussex.gdsc.core.ij.AlignImagesFFT class.
 *
 * @param combined the combined
 * @param psfs the psfs
 * @return The XYZ translations for each PSF
 */
@SuppressWarnings("unused")
private float[][] align2(ExtractedPsf combined, final ExtractedPsf[] psfs) {
    final int n = psfs.length * 3;
    final List<Future<?>> futures = new LocalList<>(n);
    final AlignImagesFft[] align = new AlignImagesFft[3];
    final Rectangle[] bounds = new Rectangle[3];
    for (int i = 0; i < 3; i++) {
        align[i] = new AlignImagesFft();
        final FloatProcessor fp1 = combined.getProjection(i, true);
        final FloatProcessor fp2 = psfs[0].getProjection(i, true);
        align[i].initialiseReference(fp1, WindowMethod.TUKEY, true);
        bounds[i] = AlignImagesFft.createHalfMaxBounds(fp1.getWidth(), fp1.getHeight(), fp2.getWidth(), fp2.getHeight());
    }
    final float[][] results = new float[psfs.length][3];
    for (int j = 0; j < psfs.length; j++) {
        final int jj = j;
        for (int i = 0; i < 3; i++) {
            final int ii = i;
            futures.add(threadPool.submit(() -> {
                final ExtractedPsf psf = psfs[jj];
                final double[] result = align[ii].align(psf.getProjection(ii, true), WindowMethod.TUKEY, bounds[ii], SubPixelMethod.CUBIC);
                // We just average the shift from each projection. There should be
                // two shifts for each dimension
                results[jj][Projection.getXDimension(ii)] -= result[0] / 2;
                results[jj][Projection.getYDimension(ii)] -= result[1] / 2;
            // psfs[index].show(TITLE + index);
            }));
        }
    }
    ConcurrencyUtils.waitForCompletionUnchecked(futures);
    return results;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) FloatProcessor(ij.process.FloatProcessor) Rectangle(java.awt.Rectangle) Future(java.util.concurrent.Future) AlignImagesFft(uk.ac.sussex.gdsc.core.ij.AlignImagesFft) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Example 68 with LocalList

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

the class PsfCreator method showAlignmentDialog.

private boolean showAlignmentDialog() {
    final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
    gd.addHelp(HelpUrls.getUrl("psf-creator"));
    gd.addMessage("Use XYZ stack alignment to create a combined PSF");
    final CalibrationWriter cw = CalibrationWriter.create(settings.getCalibration());
    // These are ignored for reset
    gd.addChoice("Alignment_mode", ALIGNMENT_MODE, settings.getAlignmentMode());
    gd.addSlider("Z_radius (px)", 0, imp.getStackSize(), settings.getAlignmentZRadius());
    gd.addChoice("PSF_type", PSF_TYPE, settings.getPsfType());
    gd.addNumericField("nm_per_pixel", cw.getNmPerPixel(), 2, 6, "nm");
    gd.addNumericField("nm_per_slice", settings.getNmPerSlice(), 0, 6, "nm");
    PeakFit.addCameraOptions(gd, PeakFit.FLAG_NO_GAIN | PeakFit.FLAG_NO_READ_NOISE, cw);
    // For reset
    final LocalList<TextField> tf = new LocalList<>();
    final LocalList<Checkbox> cb = new LocalList<>();
    tf.add(gd.addAndGetSlider("Analysis_window", 0, 8, settings.getAnalysisWindow()));
    tf.add(gd.addAndGetSlider("Smoothing", 0.1, 0.5, settings.getSmoothing()));
    tf.add(gd.addAndGetSlider("CoM_z_window", 0, 8, settings.getComWindow()));
    tf.add(gd.addAndGetSlider("CoM_border", 0, 0.5, settings.getComBorder()));
    tf.add(gd.addAndGetSlider("Alignment_magnification", 1, 8, settings.getAlignmentMagnification()));
    cb.add(gd.addAndGetCheckbox("Smooth_stack_signal", settings.getSmoothStackSignal()));
    tf.add(gd.addAndGetSlider("Max_iterations", 1, 20, settings.getMaxIterations()));
    if (settings.getInteractiveMode()) {
        cb.add(gd.addAndGetCheckbox("Check_alignments", settings.getCheckAlignments()));
    }
    tf.add(gd.addAndGetNumericField("Sub-pixel_precision", settings.getSubPixelPrecision(), -2));
    if (!settings.getInteractiveMode()) {
        tf.add(gd.addAndGetNumericField("RMSD_XY_threshold", settings.getRmsdXyThreshold(), -2));
        tf.add(gd.addAndGetNumericField("RMSD_Z_threshold", settings.getRmsdZThreshold(), -2));
        tf.add(gd.addAndGetNumericField("CoM_shift_threshold", settings.getComShiftThreshold(), -2));
    }
    if (ImageJUtils.isShowGenericDialog()) {
        gd.addAndGetButton("Reset", event -> {
            final boolean interactive = PsfCreator.this.settings.getInteractiveMode();
            final PSFCreatorSettings defaults = GuiProtosHelper.defaultPSFCreatorSettings;
            int ti = 0;
            int cbi = 0;
            tf.get(ti++).setText(Double.toString(defaults.getAnalysisWindow()));
            tf.get(ti++).setText(Double.toString(defaults.getSmoothing()));
            tf.get(ti++).setText(Integer.toString(defaults.getComWindow()));
            tf.get(ti++).setText(Double.toString(defaults.getComBorder()));
            tf.get(ti++).setText(Integer.toString(defaults.getAlignmentMagnification()));
            cb.get(cbi++).setState(defaults.getSmoothStackSignal());
            tf.get(ti++).setText(Integer.toString(defaults.getMaxIterations()));
            if (interactive) {
                cb.get(cbi++).setState(defaults.getCheckAlignments());
            }
            tf.get(ti++).setText(Double.toString(defaults.getSubPixelPrecision()));
            if (!interactive) {
                tf.get(ti++).setText(Double.toString(defaults.getRmsdXyThreshold()));
                tf.get(ti++).setText(Double.toString(defaults.getRmsdZThreshold()));
                tf.get(ti++).setText(Double.toString(defaults.getComShiftThreshold()));
            }
            // Reset later options too
            PsfCreator.this.settings.setPsfMagnification(defaults.getPsfMagnification());
            PsfCreator.this.settings.setWindow(defaults.getWindow());
            PsfCreator.this.settings.setSmoothStackSignal(defaults.getSmoothStackSignal());
            PsfCreator.this.settings.setComBorder(defaults.getComBorder());
            PsfCreator.this.settings.setCropBorder(0);
            PsfCreator.this.settings.setCropStart(0);
            PsfCreator.this.settings.setCropEnd(0);
        });
    }
    gd.showDialog();
    if (gd.wasCanceled()) {
        return false;
    }
    settings.setAlignmentMode(gd.getNextChoiceIndex());
    settings.setAlignmentZRadius((int) gd.getNextNumber());
    settings.setPsfType(gd.getNextChoiceIndex());
    cw.setNmPerPixel(gd.getNextNumber());
    settings.setNmPerSlice(gd.getNextNumber());
    cw.setCameraType(SettingsManager.getCameraTypeValues()[gd.getNextChoiceIndex()]);
    settings.setAnalysisWindow((int) gd.getNextNumber());
    settings.setSmoothing(gd.getNextNumber());
    settings.setComWindow((int) gd.getNextNumber());
    settings.setComBorder(gd.getNextNumber());
    settings.setAlignmentMagnification((int) gd.getNextNumber());
    settings.setSmoothStackSignal(gd.getNextBoolean());
    settings.setMaxIterations((int) gd.getNextNumber());
    if (settings.getInteractiveMode()) {
        checkAlignments = gd.getNextBoolean();
        settings.setCheckAlignments(checkAlignments);
    }
    settings.setSubPixelPrecision(gd.getNextNumber());
    if (!settings.getInteractiveMode()) {
        settings.setRmsdXyThreshold(gd.getNextNumber());
        settings.setRmsdZThreshold(gd.getNextNumber());
        settings.setComShiftThreshold(gd.getNextNumber());
    }
    gd.collectOptions();
    nmPerPixel = cw.getNmPerPixel();
    settings.setCalibration(cw.getBuilder());
    SettingsManager.writeSettings(settings);
    // Check arguments
    try {
        ParameterUtils.isPositive("nm/pixel", nmPerPixel);
        ParameterUtils.isPositive("nm/slice", settings.getNmPerSlice());
        // Since we do a local background estimation for each extracted PSF then we
        // do not need the bias for non sCMOS cameras.
        // if (!cw.isSCMOS())
        // Parameters.isAboveZero("Bias", cw.getBias());
        ParameterUtils.isEqualOrAbove("Projection magnification", settings.getAlignmentMagnification(), 1);
        ParameterUtils.isEqualOrAbove("Max iterations", settings.getMaxIterations(), 1);
        ParameterUtils.isEqualOrAbove("PSF magnification", settings.getPsfMagnification(), 1);
        ParameterUtils.isAbove("Smoothing", settings.getSmoothing(), 0);
        ParameterUtils.isBelow("Smoothing", settings.getSmoothing(), 1);
    } catch (final IllegalArgumentException ex) {
        IJ.error(TITLE, ex.getMessage());
        return false;
    }
    return true;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PSFCreatorSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.PSFCreatorSettings) Checkbox(java.awt.Checkbox) CalibrationWriter(uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter) TextField(java.awt.TextField) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Example 69 with LocalList

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

the class PsfCreator method align3D.

/**
 * Align the PSFs with the combined PSF using the Image2DAligner class to align the 2D max
 * intensity projections. The final alignment shift is the average of the shift from two
 * projection alignments for each dimension.
 *
 * @param combined the combined
 * @param psfs the psfs
 * @return The XYZ translations for each PSF
 */
private float[][] align3D(ExtractedPsf combined, final ExtractedPsf[] psfs) {
    // Note: For alignment we extract each PSF around the current z-centre
    // so the middle of the stack is the middle of the PSF.
    final List<Future<?>> futures = new LocalList<>(psfs.length);
    final Image3DAligner align = new Image3DAligner();
    align.setReference(combined.getImageStack(true));
    final float[][] results = new float[psfs.length][3];
    for (int j = 0; j < psfs.length; j++) {
        final int jj = j;
        futures.add(threadPool.submit(() -> {
            final ExtractedPsf psf = psfs[jj];
            final double[] result = align.copy().align(psf.getImageStack(true), 10);
            for (int i = 0; i < 3; i++) {
                results[jj][i] = (float) -result[i];
            }
        }));
    }
    ConcurrencyUtils.waitForCompletionUnchecked(futures);
    return results;
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) Image3DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image3DAligner) Future(java.util.concurrent.Future) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint)

Example 70 with LocalList

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

the class ImageJImagePeakResultsTest method addPeakResults.

private static void addPeakResults(ImageJImagePeakResults results, int[] time, float[] x, float[] y, float[] value) {
    final LocalList<PeakResult> list = new LocalList<>(x.length);
    for (int i = 0; i < x.length; i++) {
        list.add(new PeakResult(time[i], 0, 0, 0, 0, 0, 0, createParams(x[i], y[i], value[i]), null));
    }
    results.addAll(list);
}
Also used : LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult)

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