Spaces:
Runtime error
Runtime error
Martin Tomov
commited on
retain original color
Browse files
app.py
CHANGED
|
@@ -136,15 +136,12 @@ def extract_and_paste_insect(original_image: np.ndarray, detection: DetectionRes
|
|
| 136 |
insect_crop = original_image[ymin:ymax, xmin:xmax]
|
| 137 |
mask_crop = mask[ymin:ymax, xmin:xmax]
|
| 138 |
|
| 139 |
-
insect = cv2.bitwise_and(insect_crop, insect_crop, mask=mask_crop)
|
| 140 |
-
|
| 141 |
# Ensure the insect retains its original color
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
background[y_offset:y_offset + combined.shape[0], x_offset:x_offset + combined.shape[1]] = combined
|
| 148 |
|
| 149 |
def create_yellow_background_with_insects(image: np.ndarray, detections: List[DetectionResult]) -> np.ndarray:
|
| 150 |
yellow_background = np.full((image.shape[0], image.shape[1], 3), (0, 255, 255), dtype=np.uint8) # BGR for yellow
|
|
|
|
| 136 |
insect_crop = original_image[ymin:ymax, xmin:xmax]
|
| 137 |
mask_crop = mask[ymin:ymax, xmin:xmax]
|
| 138 |
|
|
|
|
|
|
|
| 139 |
# Ensure the insect retains its original color
|
| 140 |
+
insect = cv2.bitwise_and(insect_crop, insect_crop, mask=mask_crop)
|
| 141 |
+
|
| 142 |
+
# Place the insect on the yellow background
|
| 143 |
+
for c in range(3):
|
| 144 |
+
background[ymin:ymax, xmin:xmax, c] = background[ymin:ymax, xmin:xmax, c] * (1 - mask_crop) + insect[:, :, c] * mask_crop
|
|
|
|
| 145 |
|
| 146 |
def create_yellow_background_with_insects(image: np.ndarray, detections: List[DetectionResult]) -> np.ndarray:
|
| 147 |
yellow_background = np.full((image.shape[0], image.shape[1], 3), (0, 255, 255), dtype=np.uint8) # BGR for yellow
|