Search in sources :

Example 6 with FitConfiguration

use of gdsc.smlm.fitting.FitConfiguration in project GDSC-SMLM by aherbert.

the class FitEngineConfiguration method getHWHMMax.

/**
	 * Gets the maximum HWHM using the initial standard deviations
	 * <p>
	 * Note: This uses initial peak SD0 and optionally initial peak SD1 if width fitting is enabled for the second
	 * dimension.
	 *
	 * @return the HWHM max
	 */
public double getHWHMMax() {
    final FitConfiguration fitConfiguration = getFitConfiguration();
    final double initialPeakStdDev0 = fitConfiguration.getInitialPeakStdDev0();
    // Use 1 if zero to get at least a single pixel width
    double widthMax = (initialPeakStdDev0 > 0) ? initialPeakStdDev0 : 1;
    // Only use the second width if this is part of the function
    if (fitConfiguration.isWidth1Fitting()) {
        final double initialPeakStdDev1 = fitConfiguration.getInitialPeakStdDev1();
        if (initialPeakStdDev1 > 0)
            widthMax = FastMath.max(initialPeakStdDev1, widthMax);
    }
    // Get the half-width at half maximim
    return Gaussian2DFunction.SD_TO_HWHM_FACTOR * widthMax;
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration)

Example 7 with FitConfiguration

use of gdsc.smlm.fitting.FitConfiguration in project GDSC-SMLM by aherbert.

the class FitEngineConfiguration method getHWHMMin.

/**
	 * Gets the minimum HWHM using the initial standard deviations
	 * <p>
	 * Note: This uses initial peak SD0 and optionally initial peak SD1 if width fitting is enabled for the second
	 * dimension.
	 *
	 * @return the HWHM min
	 */
public double getHWHMMin() {
    final FitConfiguration fitConfiguration = getFitConfiguration();
    final double initialPeakStdDev0 = fitConfiguration.getInitialPeakStdDev0();
    // Use 1 if zero to get at least a single pixel width
    double widthMin = (initialPeakStdDev0 > 0) ? initialPeakStdDev0 : 1;
    // Only use the second width if this is part of the function
    if (fitConfiguration.isWidth1Fitting()) {
        final double initialPeakStdDev1 = fitConfiguration.getInitialPeakStdDev1();
        if (initialPeakStdDev1 > 0)
            widthMin = FastMath.min(initialPeakStdDev1, widthMin);
    }
    // Get the half-width at half maximim
    return Gaussian2DFunction.SD_TO_HWHM_FACTOR * widthMin;
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration)

Example 8 with FitConfiguration

use of gdsc.smlm.fitting.FitConfiguration in project GDSC-SMLM by aherbert.

the class SpotAnalysis method updateCurrentSlice.

private void updateCurrentSlice(int slice) {
    if (slice != currentSlice) {
        currentSlice = slice;
        double signal = getSignal(slice);
        double noise = smoothSd[slice - 1];
        currentLabel.setText(String.format("Frame %d: Signal = %s, SNR = %s", slice, Utils.rounded(signal, 4), Utils.rounded(signal / noise, 3)));
        drawProfiles();
        // Fit the PSF using a Gaussian
        float[] data2 = (float[]) rawImp.getImageStack().getProcessor(slice).getPixels();
        double[] data = Utils.toDouble(data2);
        FitConfiguration fitConfiguration = new FitConfiguration();
        fitConfiguration.setFitFunction(FitFunction.FIXED);
        fitConfiguration.setBackgroundFitting(true);
        fitConfiguration.setSignalStrength(0);
        fitConfiguration.setCoordinateShift(rawImp.getWidth() / 4.0f);
        fitConfiguration.setComputeResiduals(false);
        fitConfiguration.setComputeDeviations(false);
        Gaussian2DFitter gf = new Gaussian2DFitter(fitConfiguration);
        double[] params = new double[7];
        double psfWidth = Double.parseDouble(widthTextField.getText());
        params[Gaussian2DFunction.BACKGROUND] = smoothMean[slice - 1];
        params[Gaussian2DFunction.SIGNAL] = (gain * signal);
        params[Gaussian2DFunction.X_POSITION] = rawImp.getWidth() / 2.0f;
        params[Gaussian2DFunction.Y_POSITION] = rawImp.getHeight() / 2.0f;
        params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = psfWidth;
        FitResult fitResult = gf.fit(data, rawImp.getWidth(), rawImp.getHeight(), 1, params, new boolean[1]);
        if (fitResult.getStatus() == FitStatus.OK) {
            params = fitResult.getParameters();
            final double spotSignal = params[Gaussian2DFunction.SIGNAL] / gain;
            rawFittedLabel.setText(String.format("Raw fit: Signal = %s, SNR = %s", Utils.rounded(spotSignal, 4), Utils.rounded(spotSignal / noise, 3)));
            ImageROIPainter.addRoi(rawImp, slice, new PointRoi(params[Gaussian2DFunction.X_POSITION], params[Gaussian2DFunction.Y_POSITION]));
        } else {
            rawFittedLabel.setText("");
            rawImp.setOverlay(null);
        }
        // Fit the PSF using a Gaussian
        if (blurImp == null)
            return;
        data2 = (float[]) blurImp.getImageStack().getProcessor(slice).getPixels();
        data = Utils.toDouble(data2);
        params = new double[7];
        //float psfWidth = Float.parseFloat(widthTextField.getText());
        params[Gaussian2DFunction.BACKGROUND] = (float) smoothMean[slice - 1];
        params[Gaussian2DFunction.SIGNAL] = (float) (gain * signal);
        params[Gaussian2DFunction.X_POSITION] = rawImp.getWidth() / 2.0f;
        params[Gaussian2DFunction.Y_POSITION] = rawImp.getHeight() / 2.0f;
        params[Gaussian2DFunction.X_SD] = params[Gaussian2DFunction.Y_SD] = psfWidth;
        fitResult = gf.fit(data, rawImp.getWidth(), rawImp.getHeight(), 1, params, new boolean[1]);
        if (fitResult.getStatus() == FitStatus.OK) {
            params = fitResult.getParameters();
            final double spotSignal = params[Gaussian2DFunction.SIGNAL] / gain;
            blurFittedLabel.setText(String.format("Blur fit: Signal = %s, SNR = %s", Utils.rounded(spotSignal, 4), Utils.rounded(spotSignal / noise, 3)));
            ImageROIPainter.addRoi(blurImp, slice, new PointRoi(params[Gaussian2DFunction.X_POSITION], params[Gaussian2DFunction.Y_POSITION]));
        } else {
            blurFittedLabel.setText("");
            blurImp.setOverlay(null);
        }
    }
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration) Gaussian2DFitter(gdsc.smlm.fitting.Gaussian2DFitter) FitResult(gdsc.smlm.fitting.FitResult) PointRoi(ij.gui.PointRoi)

Example 9 with FitConfiguration

use of gdsc.smlm.fitting.FitConfiguration in project GDSC-SMLM by aherbert.

the class CreateData method createConfiguration.

/**
	 * Create a dummy calibration with the initial PSF width. This is used by the SpotInspector
	 * 
	 * @param psfWidth
	 * @return
	 */
private String createConfiguration(float psfWidth) {
    FitConfiguration fitConfig = new FitConfiguration();
    fitConfig.setInitialPeakStdDev0(psfWidth);
    fitConfig.setInitialPeakStdDev1(psfWidth);
    FitEngineConfiguration config = new FitEngineConfiguration(fitConfig);
    return XmlUtils.toXML(config);
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration) FitEngineConfiguration(gdsc.smlm.engine.FitEngineConfiguration)

Example 10 with FitConfiguration

use of gdsc.smlm.fitting.FitConfiguration in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method getScoreFilter.

private void getScoreFilter() {
    if (scoreFilter == null) {
        // Reset to default only on first run
        if (scoreDuplicateDistance == -1) {
            scoreFailCount = failCount;
            scoreDuplicateDistance = duplicateDistance;
            scoreResidualsThreshold = residualsThreshold;
        }
        // Use the best result if we have one
        FilterResult r = getBestResult();
        if (r != null) {
            scoreFilter = r.getFilter();
            scoreFailCount = r.failCount;
            scoreResidualsThreshold = r.residualsThreshold;
        } else {
            // Default to the fit config settings
            FitConfiguration tmp = new FitConfiguration();
            // So we get a MultiFilter2
            tmp.setPrecisionUsingBackground(true);
            scoreFilter = tmp.getDefaultSmartFilter();
        }
    }
}
Also used : FitConfiguration(gdsc.smlm.fitting.FitConfiguration)

Aggregations

FitConfiguration (gdsc.smlm.fitting.FitConfiguration)32 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)16 GlobalSettings (gdsc.smlm.ij.settings.GlobalSettings)8 GenericDialog (ij.gui.GenericDialog)6 Rectangle (java.awt.Rectangle)5 BasePoint (gdsc.core.match.BasePoint)4 Calibration (gdsc.smlm.results.Calibration)4 MultiPathFilter (gdsc.smlm.results.filter.MultiPathFilter)4 ExtendedGenericDialog (ij.gui.ExtendedGenericDialog)4 IJLogger (gdsc.core.ij.IJLogger)3 Gaussian2DFitter (gdsc.smlm.fitting.Gaussian2DFitter)3 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)3 DirectFilter (gdsc.smlm.results.filter.DirectFilter)3 Checkbox (java.awt.Checkbox)3 ImageExtractor (gdsc.core.utils.ImageExtractor)2 FitEngine (gdsc.smlm.engine.FitEngine)2 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)2 FitResult (gdsc.smlm.fitting.FitResult)2 FitStatus (gdsc.smlm.fitting.FitStatus)2