Merge branch 'master' into auto-exposure-gain-awb
This commit is contained in:
commit
1f1a75c02a
13 changed files with 1848 additions and 167 deletions
|
|
@ -218,10 +218,16 @@ def cleanup():
|
|||
|
||||
atexit.register(cleanup)
|
||||
|
||||
# Start the app
|
||||
if __name__ == "__main__":
|
||||
|
||||
def ofm_serve():
|
||||
# Start a debug server
|
||||
from labthings import Server
|
||||
|
||||
logging.info("Starting OpenFlexure Microscope Server...")
|
||||
server: Server = Server(app)
|
||||
server.run(host="0.0.0.0", port=5000, debug=debug_app, zeroconf=True)
|
||||
|
||||
|
||||
# Start the app if the module is run directly
|
||||
if __name__ == "__main__":
|
||||
ofm_serve()
|
||||
|
|
|
|||
|
|
@ -127,20 +127,20 @@ def monitor_sharpness(microscope: Microscope):
|
|||
m.stop()
|
||||
|
||||
|
||||
def sharpness_sum_lap2(rgb_image: np.ndarray) -> np.float:
|
||||
def sharpness_sum_lap2(rgb_image: np.ndarray) -> float:
|
||||
"""Return an image sharpness metric: sum(laplacian(image)**")"""
|
||||
image_bw: np.float = np.mean(rgb_image, 2)
|
||||
image_lap: np.float = ndimage.filters.laplace(image_bw)
|
||||
return np.mean(image_lap.astype(np.float) ** 4)
|
||||
image_bw = np.mean(rgb_image, 2)
|
||||
image_lap = ndimage.filters.laplace(image_bw)
|
||||
return float(np.mean(image_lap.astype(float) ** 4))
|
||||
|
||||
|
||||
def sharpness_edge(image: np.ndarray) -> np.float:
|
||||
def sharpness_edge(image: np.ndarray) -> float:
|
||||
"""Return a sharpness metric optimised for vertical lines"""
|
||||
gray: np.float = np.mean(image.astype(float), 2)
|
||||
gray = np.mean(image.astype(float), 2)
|
||||
n: int = 20
|
||||
edge: np.ndarray = np.array([[-1] * n + [1] * n])
|
||||
return np.sum(
|
||||
[np.sum(ndimage.filters.convolve(gray, W) ** 2) for W in [edge, edge.T]]
|
||||
return float(
|
||||
np.sum([np.sum(ndimage.filters.convolve(gray, W) ** 2) for W in [edge, edge.T]])
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ class AutofocusExtension(BaseExtension):
|
|||
|
||||
def measure_sharpness(
|
||||
self, microscope: Microscope, metric_fn: Callable = sharpness_sum_lap2
|
||||
) -> np.float:
|
||||
) -> float:
|
||||
"""Measure the sharpness of the camera's current view."""
|
||||
|
||||
if hasattr(microscope.camera, "array") and callable(
|
||||
|
|
@ -185,7 +185,7 @@ class AutofocusExtension(BaseExtension):
|
|||
dz: List[int],
|
||||
settle: float = 0.5,
|
||||
metric_fn: Callable = sharpness_sum_lap2,
|
||||
) -> Tuple[List[int], List[np.float]]:
|
||||
) -> Tuple[List[int], List[float]]:
|
||||
"""Perform a simple autofocus routine.
|
||||
The stage is moved to z positions (relative to current position) in dz,
|
||||
and at each position an image is captured and the sharpness function
|
||||
|
|
@ -197,7 +197,7 @@ class AutofocusExtension(BaseExtension):
|
|||
stage: BaseStage = microscope.stage
|
||||
|
||||
with set_properties(stage, backlash=256), stage.lock, camera.lock:
|
||||
sharpnesses: List[np.float] = []
|
||||
sharpnesses: List[float] = []
|
||||
positions: List[int] = []
|
||||
|
||||
# Some cameras may not have annotate_text. Reset if it does
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ def lst_from_channels(channels: np.ndarray) -> np.ndarray:
|
|||
|
||||
logging.info("Generating a lens shading table at %sx%s", *lst_resolution)
|
||||
lens_shading: np.ndarray = np.zeros(
|
||||
[channels.shape[0]] + lst_resolution, dtype=np.float
|
||||
[channels.shape[0]] + lst_resolution, dtype=float
|
||||
)
|
||||
for i in range(lens_shading.shape[0]):
|
||||
image_channel: np.ndarray = channels[i, :, :]
|
||||
|
|
@ -297,7 +297,7 @@ def recalibrate_camera(camera: PiCamera):
|
|||
_ = rgb_image(camera)
|
||||
|
||||
# Fix the AWB gains so the image is neutral
|
||||
channel_means = np.mean(np.mean(rgb_image(camera), axis=0, dtype=np.float), axis=0)
|
||||
channel_means = np.mean(np.mean(rgb_image(camera), axis=0, dtype=float), axis=0)
|
||||
old_gains = camera.awb_gains
|
||||
camera.awb_gains = (
|
||||
channel_means[1] / channel_means[0] * old_gains[0],
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ export default {
|
|||
stride_size: [800, 600, 10],
|
||||
fast_autofocus: true,
|
||||
autofocus_dz: 2000,
|
||||
style: "raster",
|
||||
use_video_port: false
|
||||
};
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ class JSONEncoder(LabThingsJSONEncoder):
|
|||
# Numpy integers
|
||||
elif isinstance(o, np.integer):
|
||||
return int(o)
|
||||
# Numpy floats
|
||||
elif isinstance(o, np.float):
|
||||
# Numpy floats are just Python floats
|
||||
elif isinstance(o, float):
|
||||
return float(o)
|
||||
# Numpy arrays
|
||||
elif isinstance(o, np.ndarray):
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class MissingStage(BaseStage):
|
|||
)
|
||||
displacement = move
|
||||
|
||||
initial_move = np.array(displacement, dtype=np.int)
|
||||
initial_move = np.array(displacement, dtype=np.integer)
|
||||
|
||||
self._position = list(np.array(self._position) + np.array(initial_move))
|
||||
logging.debug(np.array(self._position) + np.array(initial_move))
|
||||
|
|
|
|||
|
|
@ -277,13 +277,11 @@ class SangaDeltaStage(SangaStage):
|
|||
logging.debug(self.R_camera)
|
||||
|
||||
# Transformation matrix converting delta into cartesian
|
||||
x_fac: np.float = -1 * np.multiply(
|
||||
x_fac: float = -1 * np.multiply(
|
||||
np.divide(2, np.sqrt(3)), np.divide(self.flex_b, self.flex_h)
|
||||
)
|
||||
y_fac: np.float = -1 * np.divide(self.flex_b, self.flex_h)
|
||||
z_fac: np.float = np.multiply(
|
||||
np.divide(1, 3), np.divide(self.flex_b, self.flex_a)
|
||||
)
|
||||
y_fac: float = -1 * np.divide(self.flex_b, self.flex_h)
|
||||
z_fac: float = np.multiply(np.divide(1, 3), np.divide(self.flex_b, self.flex_a))
|
||||
|
||||
self.Tvd: np.ndarray = np.array(
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue