Search in sources :

Example 1 with Image2DAligner

use of uk.ac.sussex.gdsc.smlm.ij.utils.Image2DAligner in project GDSC-SMLM by aherbert.

the class PsfCreator method align2D.

/**
 * 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[][] align2D(ExtractedPsf combined, final ExtractedPsf[] psfs) {
    // Note: For alignment we crop the X/Y projections around the current z-centre
    // so the middle of the 2D image is the middle of the projection.
    final int n = psfs.length * 3;
    final List<Future<?>> futures = new LocalList<>(n);
    final Image2DAligner[] align = new Image2DAligner[3];
    for (int i = 0; i < 3; i++) {
        align[i] = new Image2DAligner();
        // No need to set the bounds as the PSF will be smaller
        align[i].setReference(combined.getProjection(i, true).duplicate());
    }
    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].copy().align(psf.getProjection(ii, true).duplicate(), 10);
                // 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) Future(java.util.concurrent.Future) Point(java.awt.Point) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) Image2DAligner(uk.ac.sussex.gdsc.smlm.ij.utils.Image2DAligner)

Aggregations

Point (java.awt.Point)1 Future (java.util.concurrent.Future)1 BasePoint (uk.ac.sussex.gdsc.core.match.BasePoint)1 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)1 Image2DAligner (uk.ac.sussex.gdsc.smlm.ij.utils.Image2DAligner)1