Included Richards autofocus plugin in defaults
This commit is contained in:
parent
cc36aa7593
commit
d7e19c40e2
3 changed files with 84 additions and 6 deletions
21
openflexure_microscope/plugins/default/focus_utils.py
Normal file
21
openflexure_microscope/plugins/default/focus_utils.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import numpy as np
|
||||
from scipy import ndimage
|
||||
|
||||
def decimate_to(shape, image):
|
||||
"""Decimate an image to reduce its size if it's too big."""
|
||||
decimation = np.max(np.ceil(np.array(image.shape, dtype=np.float)[:len(shape)]/np.array(shape)))
|
||||
return image[::int(decimation), ::int(decimation), ...]
|
||||
|
||||
def sharpness_sum_lap2(rgb_image):
|
||||
"""Return an image sharpness metric: sum(laplacian(image)**")"""
|
||||
#image_bw=np.mean(decimate_to((1000,1000), rgb_image),2)
|
||||
image_bw=np.mean(rgb_image, 2)
|
||||
image_lap=ndimage.filters.laplace(image_bw)
|
||||
return np.mean(image_lap.astype(np.float)**4)
|
||||
|
||||
def sharpness_edge(image):
|
||||
"""Return a sharpness metric optimised for vertical lines"""
|
||||
gray = np.mean(image.astype(float), 2)
|
||||
n = 20
|
||||
edge = np.array([[-1]*n + [1]*n])
|
||||
return np.sum([np.sum(ndimage.filters.convolve(gray,W)**2) for W in [edge, edge.T]])
|
||||
Loading…
Add table
Add a link
Reference in a new issue