askakalsky commited on
Commit
90ec8e7
·
verified ·
1 Parent(s): 88acb4e

Upload src/preprocess.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/preprocess.py +5 -0
src/preprocess.py CHANGED
@@ -46,4 +46,9 @@ def preprocess(image: np.ndarray) -> np.ndarray:
46
  _, binary = cv2.threshold(enhanced, 0, 255,
47
  cv2.THRESH_BINARY + cv2.THRESH_OTSU)
48
 
 
 
 
 
 
49
  return binary
 
46
  _, binary = cv2.threshold(enhanced, 0, 255,
47
  cv2.THRESH_BINARY + cv2.THRESH_OTSU)
48
 
49
+ # Invert if background is dark (dots should be white on black,
50
+ # matching the original Step_5_Binary preprocessing)
51
+ if binary.mean() > 127:
52
+ binary = 255 - binary
53
+
54
  return binary