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;
}
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;
}
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);
}
}
}
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);
}
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();
}
}
}
Aggregations