Search in sources :

Example 1 with ZeroKernelFilter

use of uk.ac.sussex.gdsc.smlm.filters.ZeroKernelFilter in project GDSC-SMLM by aherbert.

the class ImageKernelFilter method setNPasses.

@Override
public void setNPasses(int passes) {
    // Create the kernel from the image
    boolean build = kernelImp.getID() != lastId || settings.method != lastMethod || settings.filter != lastFilter;
    build = build || (settings.method == Settings.METHOD_SPATIAL && kf == null);
    build = build || (settings.method == Settings.METHOD_FHT && ff == null);
    if (build) {
        final Operation operation = Operation.forOrdinal(settings.filter);
        FloatProcessor fp = kernelImp.getProcessor().toFloat(0, null);
        if (settings.method == Settings.METHOD_SPATIAL) {
            if (kf == null || kernelImp.getID() != lastId || settings.zero != lastZero) {
                fp = pad(fp);
                final int kw = fp.getWidth();
                final int kh = fp.getHeight();
                final float[] kernel = (float[]) fp.getPixels();
                kf = (settings.zero) ? new ZeroKernelFilter(kernel, kw, kh) : new KernelFilter(kernel, kw, kh);
            }
            switch(operation) {
                case CONVOLUTION:
                    kf.setConvolution(true);
                    break;
                case CORRELATION:
                    kf.setConvolution(false);
                    break;
                case DECONVOLUTION:
                default:
                    // Spatial filtering does not support anything other than convolution or correlation.
                    ImageJUtils.log("Unsupported operation (%s), default to correlation", operation.getName());
                    kf.setConvolution(false);
                    break;
            }
        } else {
            if (ff == null || kernelImp.getID() != lastId) {
                final int kw = fp.getWidth();
                final int kh = fp.getHeight();
                final float[] kernel = (float[]) fp.getPixels();
                ff = new FhtFilter(kernel, kw, kh);
                ff.initialiseKernel(dataImp.getWidth(), dataImp.getHeight());
            }
            ff.setOperation(operation);
        }
        lastId = kernelImp.getID();
        lastMethod = settings.method;
        lastFilter = settings.filter;
        lastZero = settings.zero;
    }
    ticker = ImageJUtils.createTicker(passes, passes);
}
Also used : KernelFilter(uk.ac.sussex.gdsc.smlm.filters.KernelFilter) ZeroKernelFilter(uk.ac.sussex.gdsc.smlm.filters.ZeroKernelFilter) FloatProcessor(ij.process.FloatProcessor) Operation(uk.ac.sussex.gdsc.smlm.ij.filters.FhtFilter.Operation) FhtFilter(uk.ac.sussex.gdsc.smlm.ij.filters.FhtFilter) ZeroKernelFilter(uk.ac.sussex.gdsc.smlm.filters.ZeroKernelFilter)

Aggregations

FloatProcessor (ij.process.FloatProcessor)1 KernelFilter (uk.ac.sussex.gdsc.smlm.filters.KernelFilter)1 ZeroKernelFilter (uk.ac.sussex.gdsc.smlm.filters.ZeroKernelFilter)1 FhtFilter (uk.ac.sussex.gdsc.smlm.ij.filters.FhtFilter)1 Operation (uk.ac.sussex.gdsc.smlm.ij.filters.FhtFilter.Operation)1