Fahimeh Orvati Nia
commited on
Commit
·
34280b7
1
Parent(s):
69cba14
UPDATE
Browse files
sorghum_pipeline/features/morphology.py
CHANGED
|
@@ -79,8 +79,8 @@ class MorphologyExtractor:
|
|
| 79 |
else:
|
| 80 |
features['traits']['plant_height_cm'] = 0.0
|
| 81 |
|
| 82 |
-
# YOLO tips overlay (optional)
|
| 83 |
-
yolo_img, tips = self._detect_yolo_tips(rgb,
|
| 84 |
if yolo_img is not None:
|
| 85 |
features['images']['yolo_tips'] = yolo_img
|
| 86 |
features['traits']['num_yolo_tips'] = int(len(tips) if tips is not None else 0)
|
|
@@ -170,11 +170,24 @@ class MorphologyExtractor:
|
|
| 170 |
return vis
|
| 171 |
|
| 172 |
def _create_white_background_overlay(self, rgb: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
| 173 |
-
"""Return white background with plant pixels in original colors.
|
|
|
|
|
|
|
| 174 |
img_no_bg = rgb.copy()
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
overlay = np.full_like(rgb, 255, dtype=np.uint8)
|
| 177 |
-
overlay[
|
| 178 |
return overlay
|
| 179 |
|
| 180 |
def _detect_yolo_tips(self, rgb: np.ndarray, mask: np.ndarray):
|
|
|
|
| 79 |
else:
|
| 80 |
features['traits']['plant_height_cm'] = 0.0
|
| 81 |
|
| 82 |
+
# YOLO tips overlay (optional) — use the original mask (same as frontend)
|
| 83 |
+
yolo_img, tips = self._detect_yolo_tips(rgb, mask)
|
| 84 |
if yolo_img is not None:
|
| 85 |
features['images']['yolo_tips'] = yolo_img
|
| 86 |
features['traits']['num_yolo_tips'] = int(len(tips) if tips is not None else 0)
|
|
|
|
| 170 |
return vis
|
| 171 |
|
| 172 |
def _create_white_background_overlay(self, rgb: np.ndarray, mask: np.ndarray) -> np.ndarray:
|
| 173 |
+
"""Return white background with plant pixels in original colors.
|
| 174 |
+
The mask here is normalized to a single-channel binary mask so it matches the frontend mask behavior.
|
| 175 |
+
"""
|
| 176 |
img_no_bg = rgb.copy()
|
| 177 |
+
# Normalize mask to single-channel binary
|
| 178 |
+
if mask is None:
|
| 179 |
+
bin_mask = None
|
| 180 |
+
else:
|
| 181 |
+
m = mask
|
| 182 |
+
if m.ndim == 3:
|
| 183 |
+
m = cv2.cvtColor(m, cv2.COLOR_BGR2GRAY)
|
| 184 |
+
m = m.astype(np.uint8)
|
| 185 |
+
_, bin_mask = cv2.threshold(m, 0, 255, cv2.THRESH_BINARY)
|
| 186 |
+
if bin_mask is None:
|
| 187 |
+
return np.full_like(rgb, 255, dtype=np.uint8)
|
| 188 |
+
img_no_bg[bin_mask == 0] = 0
|
| 189 |
overlay = np.full_like(rgb, 255, dtype=np.uint8)
|
| 190 |
+
overlay[bin_mask > 0] = img_no_bg[bin_mask > 0]
|
| 191 |
return overlay
|
| 192 |
|
| 193 |
def _detect_yolo_tips(self, rgb: np.ndarray, mask: np.ndarray):
|