From aa704239ed318ff6e5ec72070a4e8dce8e3ddf7a Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 21 Nov 2025 12:43:40 +0100 Subject: [PATCH] Modify background detect check to check for all squares having no std. As LUV appears insensitive to low colour noise --- src/openflexure_microscope_server/background_detect.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/openflexure_microscope_server/background_detect.py b/src/openflexure_microscope_server/background_detect.py index 43f840db..5438b761 100644 --- a/src/openflexure_microscope_server/background_detect.py +++ b/src/openflexure_microscope_server/background_detect.py @@ -337,11 +337,13 @@ class ChannelDeviationLUV(BackgroundDetectAlgorithm): image_luv = cv2.cvtColor(image, cv2.COLOR_RGB2LUV) mu = np.zeros(3) - std = np.median(_chunked_stds(image_luv, 8, 8), axis=(0, 1)) - if np.any(std == 0): + c_stds = _chunked_stds(image_luv, 8, 8) + channel_blank = np.all(c_stds == 0, axis=(0, 1)) + if np.any(channel_blank): raise ChannelBlankError("Some LUV channels have no standard devaition.") - std = np.maximum(std, self.min_stds) + std = np.median(c_stds, axis=(0, 1)) + std = np.maximum(std, self.min_stds) self.background_data = ChannelDistributions( means=mu.tolist(), standard_deviations=std.tolist() )