Apply suggestions from code review of branch scanning-stability
Co-authored-by: Joe Knapper <joe.knapper@glasgow.ac.uk>
This commit is contained in:
parent
23f87869ac
commit
38b8c5baa5
2 changed files with 9 additions and 8 deletions
|
|
@ -267,8 +267,8 @@ class ColourChannelDetectLUV(BackgroundDetectAlgorithm):
|
|||
class ChannelDeviationLUV(BackgroundDetectAlgorithm):
|
||||
"""Compare the standard deviations of the LUV channels in a grid to background data.
|
||||
|
||||
This uses an LUV colour space, each image is divided into an 8x8 grid of images
|
||||
each the standard deviation of each channel of each image is calculates and compared
|
||||
Using an LUV colour space, each image is divided into an 8x8 grid of images.
|
||||
The standard deviation of each channel of each image is calculated and compared
|
||||
to the median standard deviation for a grid of background images.
|
||||
"""
|
||||
|
||||
|
|
@ -295,11 +295,11 @@ class ChannelDeviationLUV(BackgroundDetectAlgorithm):
|
|||
u_cut = bg_stds[1] * self.settings.channel_tolerance
|
||||
v_cut = bg_stds[2] * self.settings.channel_tolerance
|
||||
|
||||
decisions = (
|
||||
populated_regions = (
|
||||
(stds[:, :, 0] > l_cut) | (stds[:, :, 1] > u_cut) | (stds[:, :, 2] > v_cut)
|
||||
)
|
||||
|
||||
return float(100 * np.sum(decisions) / 64)
|
||||
return float(100 * np.sum(populated_regions) / 64)
|
||||
|
||||
def image_is_sample(self, image: np.ndarray) -> tuple[bool, str]:
|
||||
"""Label the current image as either background or sample.
|
||||
|
|
@ -330,12 +330,12 @@ class ChannelDeviationLUV(BackgroundDetectAlgorithm):
|
|||
|
||||
|
||||
def _chunked_stds(img: np.ndarray, n_rows: int = 8, n_cols: int = 8) -> np.ndarray:
|
||||
"""Split image into a grid and calculated std of each channel in each chunk.
|
||||
"""Split image into a grid and calculate std of each channel in each chunk.
|
||||
|
||||
:param img: The image to analyse
|
||||
:param n_rows: The number of rows in the grid
|
||||
:param n_cols: The number of cols in the grid
|
||||
:return: A nummpy array of the grid of standard deviations.
|
||||
:return: A numpy array of the grid of standard deviations.
|
||||
"""
|
||||
h, w = img.shape[:2]
|
||||
row_height = h // n_rows
|
||||
|
|
|
|||
|
|
@ -812,7 +812,7 @@ class AutofocusThing(lt.Thing):
|
|||
return "restart", capture_id
|
||||
return "continue", capture_id
|
||||
|
||||
# Fint the peak
|
||||
# Fit the peak
|
||||
x = range(n_imgs)
|
||||
coeffs, cov = np.polyfit(x, sharpnesses, deg=2, cov=True)
|
||||
a = float(coeffs[0])
|
||||
|
|
@ -833,7 +833,8 @@ class AutofocusThing(lt.Thing):
|
|||
# the stack ie for a stack of 7 images, best image must be between 3rd and 5th
|
||||
edge_size = 2
|
||||
|
||||
# Check both the peak from fitting and the sharpest image are not the
|
||||
# Check both the peak from fitting and the sharpest image are not at the
|
||||
# edge of the stack.
|
||||
if turning < edge_size - 0.5 or sharpest_index < edge_size:
|
||||
return "restart", capture_id
|
||||
if turning > n_imgs - (edge_size - 0.5) or sharpest_index >= n_imgs - edge_size:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue