From 77b9503ce830bf68f504e3ab392fe29b17d7ecf7 Mon Sep 17 00:00:00 2001
From: amitjans <amitjans@ethz.ch>
Date: Tue, 1 Jun 2021 10:25:28 +0200
Subject: [PATCH] Only use region of interest in detect_ion_cloud()

---
 tools.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools.py b/tools.py
index fe274d5..58a1cf3 100644
--- a/tools.py
+++ b/tools.py
@@ -200,12 +200,13 @@ def detect_ion_cloud(image):
     Measure the area of the biggest contour of the image. If it is larger than a certain threshold
     consider an ion cloud.
     """
-    image = np.array(image)
+    region = settings.REGION  # crop region of interest
+    image = np.array(image[region[0, 1]:region[1, 1], region[0, 0]:region[1, 0]])
     image = gaussian(image, sigma=7)
     _, binary = cv2.threshold(image, thresh=image.max()*0.8, maxval=255, type=cv2.THRESH_BINARY)
     contours, _ = cv2.findContours(np.uint8(binary), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
     max_contour = max(contours, key=cv2.contourArea)
-    is_ion_cloud = bool(settings.AREA_THS < cv2.contourArea(max_contour) < np.size(image)/2)
+    is_ion_cloud = settings.AREA_THS < cv2.contourArea(max_contour) < np.size(image)/2
 
     return is_ion_cloud
 
-- 
GitLab