From b340da488ee98d6ba3a8b6ff3b6c2c32d7317ce6 Mon Sep 17 00:00:00 2001 From: jaknapper Date: Tue, 25 Feb 2025 15:17:44 +0000 Subject: [PATCH] Use the UV channels only to determine if an area is background or sample --- src/openflexure_microscope_server/things/smart_scan.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 3c9dd7a9..cdd0780f 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -259,9 +259,12 @@ class BackgroundDetectThing(Thing): raise RuntimeError( "Background is not set: you need to calibrate background detection." ) + # This image is in LUV space. But the brightness (L) often changes as the + # height of the sample changes. Hence in the line below we are only using + # the UV (colour) channels. return np.all( - np.abs(image - np.array(d.means)[np.newaxis, np.newaxis, :]) - < np.array(d.standard_deviations)[np.newaxis, np.newaxis, :] + np.abs(image[:, :, 1:] - np.array(d.means[1:])[np.newaxis, np.newaxis, :]) + < np.array(d.standard_deviations[1:])[np.newaxis, np.newaxis, :] * self.tolerance, axis=2, )