use of uk.ac.sussex.gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.
the class PeakFit method showResults.
/**
* Show results.
*/
protected void showResults() {
IJ.showProgress(1.0);
if (time >= 0) {
if (silent) {
results.end();
return;
}
// Check if we are sorting
IJ.showStatus("Finalising results ...");
for (final PeakResults r : results.toArray()) {
if (r instanceof MemoryPeakResults) {
if (((MemoryPeakResults) r).isSortAfterEnd()) {
IJ.showStatus("Sorting " + r.size() + " results ...");
}
break;
}
}
results.end();
final String textTime = TextUtils.nanosToString(time);
final String textRunTime = TextUtils.nanosToString(runTime);
final int size = getSize();
final String message = String.format("%s. Total fitting time = %s. Run time = %s", TextUtils.pleural(size, "localisation"), textTime, textRunTime);
if (resultsSettings.getLogProgress()) {
IJ.log(LOG_SPACER);
}
IJ.log(message);
IJ.showStatus(message);
} else {
IJ.showStatus("");
}
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.
the class PeakFit method addSingleFrameOverlay.
private void addSingleFrameOverlay() {
// If a single frame was processed add the peaks as an overlay if they are in memory
ImagePlus localImp = this.imp;
if (fitMaxima && singleFrame > 0 && source instanceof IJImageSource) {
final String title = source.getName();
localImp = WindowManager.getImage(title);
}
if (singleFrame > 0 && localImp != null) {
MemoryPeakResults memoryResults = null;
for (final PeakResults r : this.results.toArray()) {
if (r instanceof MemoryPeakResults) {
memoryResults = (MemoryPeakResults) r;
break;
}
}
if (memoryResults == null || memoryResults.size() == 0) {
return;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("Add the fitted localisations as an overlay?");
gd.showDialog();
if (!gd.wasOKed()) {
return;
}
final LUT lut = LutHelper.createLut(LutColour.ICE);
final Overlay o = new Overlay();
final int size = memoryResults.size();
final Counter j = new Counter(size);
final ImagePlus finalImp = localImp;
memoryResults.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (x, y) -> {
final PointRoi roi = new OffsetPointRoi(x, y);
final Color c = LutHelper.getColour(lut, j.decrementAndGet(), size);
roi.setStrokeColor(c);
roi.setFillColor(c);
if (finalImp.getStackSize() > 1) {
roi.setPosition(singleFrame);
}
o.add(roi);
});
localImp.setOverlay(o);
localImp.getWindow().toFront();
}
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.
the class ResultsManager method addFileResults.
/**
* Adds the file results.
*
* @param resultsList the results list
* @param resultsSettings the results settings
* @param resultsFilename the results filename
* @param showDeviations the show deviations
* @param showEndFrame the show end frame
* @param showId the show id
* @param showCategory the show category
* @return the peak results
*/
public static PeakResults addFileResults(PeakResultsList resultsList, ResultsFileSettings resultsSettings, String resultsFilename, boolean showDeviations, boolean showEndFrame, boolean showId, boolean showCategory) {
if (resultsSettings.getFileFormatValue() > 0 && resultsFilename != null) {
final File file = new File(resultsFilename);
final File parent = file.getParentFile();
if (parent != null && parent.exists()) {
PeakResults results;
switch(resultsSettings.getFileFormat()) {
case BINARY:
results = new BinaryFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
break;
case TEXT:
final TextFilePeakResults f = new TextFilePeakResults(resultsFilename, showDeviations, showEndFrame, showId, resultsSettings.getShowPrecision(), showCategory);
f.setDistanceUnit(resultsSettings.getDistanceUnit());
f.setIntensityUnit(resultsSettings.getIntensityUnit());
f.setAngleUnit(resultsSettings.getAngleUnit());
f.setComputePrecision(true);
results = f;
break;
case MALK:
results = new MalkFilePeakResults(resultsFilename);
break;
case TSF:
results = new TsfPeakResultsWriter(resultsFilename);
break;
default:
throw new IllegalArgumentException("Unsupported file format: " + resultsSettings.getFileFormat());
}
resultsList.addOutput(results);
return results;
}
}
return null;
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.
the class PeakFit method createFitEngine.
/**
* Creates a fitting engine using the current configuration.
*
* @param numberOfThreads the number of threads
* @param queue the queue
* @param queueSize the queue size
* @return The fiting engine
*/
public FitEngine createFitEngine(int numberOfThreads, FitQueue queue, int queueSize) {
// Ensure thread safety
final PeakResultsList list = (numberOfThreads > 1) ? results.getThreadSafeList() : results;
// Reduce to single object for speed
final PeakResults r = (results.numberOfOutputs() == 1) ? list.toArray()[0] : list;
// Update the configuration
if (!updateFitConfiguration(config)) {
return null;
}
final FitEngine engine = FitEngine.create(config, r, numberOfThreads, queue, queueSize);
// Write settings out to the IJ log
if (resultsSettings.getLogProgress()) {
IJ.log(LOG_SPACER);
IJ.log("Peak Fit");
IJ.log(LOG_SPACER);
ImageJUtils.log("Initial Peak SD = %s,%s", MathUtils.rounded(fitConfig.getInitialXSd()), MathUtils.rounded(fitConfig.getInitialYSd()));
final SpotFilter spotFilter = engine.getSpotFilter();
IJ.log("Spot Filter = " + spotFilter.getDescription());
final int w = 2 * engine.getFitting() + 1;
ImageJUtils.log("Fit window = %d x %d", w, w);
if (!fitConfig.isDisableSimpleFilter()) {
IJ.log("Coordinate shift = " + MathUtils.rounded(config.getFitConfiguration().getCoordinateShift()));
IJ.log("Signal strength = " + MathUtils.rounded(fitConfig.getSignalStrength()));
}
if (fitConfig.isDirectFilter()) {
IJ.log("Smart filter = " + fitConfig.getSmartFilter().getDescription());
}
if (extraOptions) {
IJ.log("Noise = " + MathUtils.rounded(fitConfig.getNoise()));
}
IJ.log("Width factor = " + MathUtils.rounded(fitConfig.getMaxWidthFactor()));
IJ.log(LOG_SPACER);
}
return engine;
}
use of uk.ac.sussex.gdsc.smlm.results.PeakResults in project GDSC-SMLM by aherbert.
the class ResultsMatchCalculator method savePairs.
private void savePairs(MemoryPeakResults results1, MemoryPeakResults results2, List<PointPair> allMatches) {
if (!settings.savePairs) {
return;
}
// Get the directory
final String directory = ImageJUtils.getDirectory("Pairs_directory", settings.pairsDirectory);
if (directory == null) {
return;
}
settings.pairsDirectory = directory;
final double[] distanceThresholds = getDistances(settings.distanceThreshold, settings.increments, settings.delta);
// Create output files for each distance band
final PeakResults[] output1 = new PeakResults[distanceThresholds.length];
final PeakResults[] output2 = new PeakResults[distanceThresholds.length];
double high = 0;
for (int i = 0; i < distanceThresholds.length; i++) {
final double low = high;
high = distanceThresholds[i];
output1[i] = createFilePeakResults(directory, 1, results1, low, high);
output2[i] = createFilePeakResults(directory, 2, results2, low, high);
}
// Square the thresholds
SimpleArrayUtils.apply(distanceThresholds, v -> v * v);
final double[] pairDistances = getPairDistances(allMatches);
int index = 0;
for (final PointPair pair : allMatches) {
final int insert = search(distanceThresholds, pairDistances[index++]);
if (insert != -1) {
final PeakResult r1 = ((PeakResultPoint) pair.getPoint1()).getPeakResult();
final PeakResult r2 = ((PeakResultPoint) pair.getPoint2()).getPeakResult();
output1[insert].add(r1);
output2[insert].add(r2);
}
}
for (int i = 0; i < output1.length; i++) {
output1[i].end();
output2[i].end();
}
}
Aggregations