Went on a PEP-8 rampage

This commit is contained in:
Joel Collins 2019-01-31 17:20:46 +00:00
parent f99ad30fb6
commit 0948c9308a
36 changed files with 186 additions and 218 deletions

View file

@ -3,21 +3,21 @@ import numpy as np
from openflexure_microscope.api.v1.views import MicroscopeViewPlugin
from openflexure_microscope.api.utilities import JsonPayload
from flask import request, Response, escape, jsonify
from flask import request, jsonify
import logging
class MeasureSharpnessAPI(MicroscopeViewPlugin):
def post(self):
payload = JsonPayload(request)
return jsonify({'sharpness': self.plugin.measure_sharpness()})
class AutofocusAPI(MicroscopeViewPlugin):
def post(self):
payload = JsonPayload(request)
# Figure out the range of z values to use
dz = payload.param("dz", default=np.linspace(-300,300,7), convert=np.array)
dz = payload.param("dz", default=np.linspace(-300, 300, 7), convert=np.array)
print("Running autofocus...")
task = self.microscope.task.start(self.plugin.autofocus, dz)

View file

@ -1,21 +1,24 @@
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)
# 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]])
return np.sum([np.sum(ndimage.filters.convolve(gray, W)**2) for W in [edge, edge.T]])

View file

@ -34,7 +34,7 @@ class AutofocusPlugin(MicroscopePlugin):
positions = []
camera.annotate_text = ""
for i in stage.scan_z(dz, return_to_start=False):
for _ in stage.scan_z(dz, return_to_start=False):
positions.append(stage.position[2])
time.sleep(settle)
sharpnesses.append(self.measure_sharpness(metric_fn))
@ -46,4 +46,4 @@ class AutofocusPlugin(MicroscopePlugin):
def measure_sharpness(self, metric_fn=sharpness_sum_lap2):
"""Measure the sharpness of the camera's current view."""
return metric_fn(self.microscope.camera.array(use_video_port=True, resize=(640,480)))
return metric_fn(self.microscope.camera.array(use_video_port=True, resize=(640, 480)))