def get_fft_filter(image_shape, min_feature, max_feature, microns_per_pixel): fftw_hints = pathlib.Path(__file__).parent / 'fftw_hints' if fftw_hints.exists(): fast_fft.load_plan_hints(str(fftw_hints)) fft_filter = fast_fft.SpatialFilter(image_shape, period_range=(min_feature, max_feature), spacing=microns_per_pixel, order=2, keep_dc=False, threads=1, better_plan=True) fast_fft.store_plan_hints(str(fftw_hints)) return fft_filter
import sqlite3 import sys import time DPATHSTR = { 'darwin' : '/Volumes/bulkdata/Sinha_Drew/2015.11.13_ZPL8Prelim3' }.get(sys.platform, '/mnt/bulkdata/Sinha_Drew/2015.11.13_ZPL8Prelim3') DPATH = Path(DPATHSTR) from rpc_acquisition.scope.device.autofocus import MultiBrenner import os.path from zplib.image import fast_fft FFTW_WISDOM = os.path.expanduser('~/fftw_wisdom') if os.path.exists(FFTW_WISDOM): fast_fft.load_plan_hints(FFTW_WISDOM) class AutofocusMetric: def __init__(self, shape): pass def metric(self, image): raise NotImplementedError() class Brenner(AutofocusMetric): def metric(self, image): image = image.astype(numpy.float32) # otherwise can get overflow in the squaring and summation xd = image.astype(numpy.float32) yd = image.astype(numpy.float32) x_diffs = (image[2:, :] - image[:-2, :])**2 xd[1:-1, :] = x_diffs
import freeimage from zplib.image import fast_fft from ..util import transfer_ism_buffer from ..util import logging from ..config import scope_configuration from . import andor from .leica import stage from . import iotool logger = logging.get_logger(__name__) FFTW_WISDOM = scope_configuration.CONFIG_DIR / 'fftw_wisdom' if FFTW_WISDOM.exists(): loaded = fast_fft.load_plan_hints(str(FFTW_WISDOM)) if loaded: logger.debug('FFTW wisdom loaded') else: logger.warning('FFTW wisdom file exists, but some wisdom could not be loaded (FFTW version mismatch?)') else: logger.warning('No FFTW wisdom found!') @functools.lru_cache(maxsize=16) def _get_filter(shape, period_range): timer = threading.Timer(1, logger.warning, ['Slow construction of FFTW filter for image shape {} (likely no cached plan could be found). May take >30 minutes!', shape]) timer.start() fft_filter = fast_fft.SpatialFilter(shape, period_range, precision=32, threads=6, better_plan=True) if timer.is_alive(): timer.cancel() else: # timer went off and warning was issued...