diff --git a/tools.py b/tools.py index fe274d5dbdc326e3aa3a8f21398fe990c3fc4d56..58a1cf3b3912a1382a02186ab4cb93bfa13ec868 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