Improve the stability of scanning
This MR was made in response to #600 (closed). It is to fix #599 (closed) and #600 (closed). Firstly it ensures smart stack exits when expected. It also to make smart stack more stringent, and creates a new default background detect method that is more robust now that our white balance is much better. This stops us z-stacking on background.
Closes #599 (closed) #600 (closed)
This MR contains the following
- Add new background detect method that is based on standard deviation of the each LUV channel within the an 8x8 grid. (See below)
- Adjust UI to give the name of the background detect method. (No way to change it yet).
- Adjust the base camera Thing to warn rather than error if there is no background detector with a matching name when setting. This stops the server failing to boot with settings that don't match the current background detectors.
- Add minimum standard deviations to both background detectors.
- Error if the standard deviation of any channel is zero (ad this is the camera not being ready). In full auto calibrate catch this error, wait, and try again up to 3 tries total.
- Simplify the code within
looping autofocus. - Ensure that smart stack exits after
max_attempts - Add extra checks to z-stack:
- Perform quadratic fit to check that the trace looks like a peak (95% confidence)
- Check that the fitted turning point is within the central range
- Check the trace (once noise fluctuations are removed) has one turning point only. Optional This is optional as it may fail for thicker samples. Nothing exposed yet to toggle this option.
- Adjust smart stack so that it knows if it fails and doesn't try to save image
- If no image is not saved do not mark the location as imaged.
UI Changes:
Background Detect Visualisation
(Code for visualisation is in a notebook here)[visualisation_and_workbooks!2]
Background detect looks as the magnitude of the standard deviation within each square of an 8x8 grid. This is compared to the median for a square taken from background detect image. The number of squares are used to give the percentage.
It works well on H&E stained samples:

And pretty well on sparse samples:

It does less well if samples are out of focus, but it depends on how out of focus:

This one is only detected as 12.5% sample:

This could partly be mitigated by focussing after any longer moves.
Created #618
Before Merge:
-
Add minimum background values -
Prevent erroring if the set background detector doesn't exist on load -
Split up stack testing and make some of it optional
Merge checklist:
-
All new/changed functions have up to date typehints and docstrings -
Any UI updates have a before and after screenshot in the MR description -
Unit testing of new functionality has similar or better coverage than similar existing code -
This code has been tested on a microscope -
Webapp has been recompiled, with aesthetic changes checked in light and dark mode (if changed) -
With updated settings JSON (if changed) -
SmartScan and live stitching work
-

