Search in sources :

Example 1 with ZProjector

use of ij.plugin.ZProjector in project GDSC-SMLM by aherbert.

the class SpotAnalysis method createProfile.

private void createProfile(ImagePlus imp, Rectangle bounds, double psfWidth, double blur) {
    areaBounds = bounds;
    this.imp = imp;
    area = bounds.width * bounds.height;
    clearSelectedFrames();
    // Get a profile through the images
    IJ.showStatus("Calculating raw profile");
    final int nSlices = imp.getStackSize();
    ImageStack rawSpot = new ImageStack(bounds.width, bounds.height, nSlices);
    double[][] profile = extractSpotProfile(imp, bounds, rawSpot);
    // Retain the existing display range
    double min = 0, max = Double.POSITIVE_INFINITY;
    if (rawImp != null) {
        min = rawImp.getDisplayRangeMin();
        max = rawImp.getDisplayRangeMax();
    }
    rawImp = showSpot(rawSpotTitle, rawSpot);
    if (max != Double.POSITIVE_INFINITY) {
        rawImp.setDisplayRange(min, max);
    }
    rawMean = profile[0];
    rawSd = profile[1];
    // Check if there are fitted results in memory
    addCandidateFrames(imp.getTitle());
    updateProfilePlots();
    if (blur > 0) {
        IJ.showStatus("Calculating blur ...");
        ImageStack stack = imp.getImageStack();
        ImageStack newStack = new ImageStack(stack.getWidth(), stack.getHeight(), stack.getSize());
        // Multi-thread the blur stage
        ExecutorService threadPool = Executors.newFixedThreadPool(Prefs.getThreads());
        List<Future<?>> futures = new LinkedList<Future<?>>();
        Utils.setShowProgress(false);
        blurCount = 0;
        // TODO - See if this is faster if processing multiple slices in each worker
        int slices = 5;
        for (int n = 1; n <= nSlices; n += slices) {
            futures.add(threadPool.submit(new BlurWorker(stack, n, slices, bounds, blur * psfWidth, newStack)));
        }
        IJ.showStatus("Calculating blur ... Finishing");
        Utils.waitForCompletion(futures);
        threadPool.shutdown();
        Utils.setShowProgress(false);
        IJ.showStatus("Calculating blur ... Drawing");
        ImageStack blurSpot = new ImageStack(bounds.width, bounds.height, nSlices);
        extractSpotProfile(new ImagePlus("Blur", newStack), bounds, blurSpot);
        // Retain the existing display range
        max = Double.POSITIVE_INFINITY;
        if (blurImp != null) {
            min = blurImp.getDisplayRangeMin();
            max = blurImp.getDisplayRangeMax();
        }
        blurImp = showSpot(blurSpotTitle, blurSpot);
        if (max != Double.POSITIVE_INFINITY) {
            blurImp.setDisplayRange(min, max);
        }
        IJ.showStatus("");
    } else {
        blurImp = null;
    }
    // Add a z-projection of the blur/original image
    ZProjector project = new ZProjector((blurImp == null) ? rawImp : blurImp);
    project.setMethod(ZProjector.AVG_METHOD);
    project.doProjection();
    showSpot(avgSpotTitle, project.getProjection().getImageStack());
    if (!candidateFrames.isEmpty())
        // Set the first candidate frame
        rawImp.setSlice(candidateFrames.get(0));
    else
        updateCurrentSlice(rawImp.getCurrentSlice());
    IJ.showStatus("");
}
Also used : ImageStack(ij.ImageStack) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ImagePlus(ij.ImagePlus) Point(java.awt.Point) LinkedList(java.util.LinkedList) ZProjector(ij.plugin.ZProjector)

Example 2 with ZProjector

use of ij.plugin.ZProjector in project GDSC-SMLM by aherbert.

the class ImageBackground method getProjection.

private ImageProcessor getProjection() {
    // Get median intensity projection
    ZProjector p = new ZProjector(imp);
    p.setMethod(ZProjector.MEDIAN_METHOD);
    p.doProjection();
    ImageProcessor median = p.getProjection().getProcessor();
    return median;
}
Also used : ImageProcessor(ij.process.ImageProcessor) ZProjector(ij.plugin.ZProjector)

Aggregations

ZProjector (ij.plugin.ZProjector)2 ImagePlus (ij.ImagePlus)1 ImageStack (ij.ImageStack)1 ImageProcessor (ij.process.ImageProcessor)1 Point (java.awt.Point)1 LinkedList (java.util.LinkedList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1