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