emilios commited on
Commit
597c751
1 Parent(s): cb472b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -3,9 +3,21 @@ import cv2
3
 
4
 
5
  def inference(img):
6
- my_result = cv2.erode(img,(1,1))
7
- my_result = cv2.dilate(my_result,(1,1))
8
- return my_result
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # For information on Interfaces, head to https://gradio.app/docs/
11
  # For user guides, head to https://gradio.app/guides/
 
3
 
4
 
5
  def inference(img):
6
+ #my_result = cv2.erode(img,(1,1))
7
+ #my_result = cv2.dilate(my_result,(1,1))
8
+ # https://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.remove_small_objects
9
+ # my_result = cv2.remove_small_objects(binarized.astype(bool), min_size=2, connectivity=2).astype(int)
10
+ img_bw = 255*(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) > 5).astype('uint8')
11
+
12
+ se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
13
+ se2 = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
14
+ mask = cv2.morphologyEx(img_bw, cv2.MORPH_CLOSE, se1)
15
+ mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, se2)
16
+
17
+ mask = np.dstack([mask, mask, mask]) / 255
18
+ out = img * mask
19
+
20
+ return out
21
 
22
  # For information on Interfaces, head to https://gradio.app/docs/
23
  # For user guides, head to https://gradio.app/guides/