Martin Tomov commited on
Commit
e692102
·
verified ·
1 Parent(s): 3814c3a

np.where experiment

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -138,10 +138,10 @@ def extract_and_paste_insect(original_image: np.ndarray, detection: DetectionRes
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
 
138
 
139
  # Ensure the insect retains its original color
140
  insect = cv2.bitwise_and(insect_crop, insect_crop, mask=mask_crop)
141
+
142
+ # np.where to ensure correct blending
143
  for c in range(3):
144
+ background[ymin:ymax, xmin:xmax, c] = np.where(mask_crop, insect[:, :, c], background[ymin:ymax, xmin:xmax, c])
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