Fahimeh Orvati Nia commited on
Commit
a913fdb
·
1 Parent(s): 4c1c4a7

update mask_handler

Browse files
sorghum_pipeline/data/mask_handler.py CHANGED
@@ -15,7 +15,19 @@ class MaskHandler:
15
  """Apply mask to image."""
16
  if mask is None:
17
  return image
 
 
 
 
 
18
  if mask.shape[:2] != image.shape[:2]:
19
  mask = cv2.resize(mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
 
 
20
  binary = (mask > 0).astype(np.uint8) * 255
 
 
 
 
 
21
  return cv2.bitwise_and(image, image, mask=binary)
 
15
  """Apply mask to image."""
16
  if mask is None:
17
  return image
18
+
19
+ # Ensure mask is uint8
20
+ mask = mask.astype(np.uint8)
21
+
22
+ # Resize mask to match image if needed
23
  if mask.shape[:2] != image.shape[:2]:
24
  mask = cv2.resize(mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
25
+
26
+ # Create binary mask
27
  binary = (mask > 0).astype(np.uint8) * 255
28
+
29
+ # Ensure binary mask is single channel and matches image dimensions
30
+ if binary.shape[:2] != image.shape[:2]:
31
+ binary = cv2.resize(binary, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
32
+
33
  return cv2.bitwise_and(image, image, mask=binary)