emilios commited on
Commit
a76dcb0
·
verified ·
1 Parent(s): 6863937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -24
app.py CHANGED
@@ -1,31 +1,19 @@
1
- import gradio
2
- import cv2
3
  import numpy as np
4
-
5
 
6
 
7
  def inference(img):
8
- #out = cv2.erode(img,(15,15))
9
- #out = cv2.dilate(out,(55,55))
10
- # https://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.remove_small_objects
11
- # my_result = cv2.remove_small_objects(binarized.astype(bool), min_size=2, connectivity=2).astype(int)
12
-
13
- #img_bw = 255*(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) > 5).astype('uint8')
14
- #se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
15
- #se2 = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
16
- #mask = cv2.morphologyEx(img_bw, cv2.MORPH_CLOSE, se1)
17
- #mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, se2)
18
- #mask = np.dstack([mask, mask, mask]) / 255
19
- #out = img * mask
20
 
21
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY ) # grayscale
22
- #out = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,133,9)
23
- out = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,221,3)
24
- out = cv2.dilate(out,(55,55))
25
 
26
-
27
- #kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernelSize)
28
- #opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
29
 
30
  return out
31
 
@@ -36,8 +24,8 @@ iface = gradio.Interface(
36
  fn=inference,
37
  inputs='image',
38
  outputs='image',
39
- title='Noise Removal',
40
- description='Remove Noise with OpenCV and Adaptial Gaussian!',
41
  examples=["detail_with_lines_and_noise.jpg", "lama.webp", "dT4KW.png"])
42
  #examples=["detail_with_lines_and_noise.jpg", "lama.webp", "test_lines.jpg","llama.jpg", "dT4KW.png"])
43
 
 
1
+ import matplotlib.pyplot as plt
2
+ from skimage import morphology
3
  import numpy as np
4
+ import skimage
5
 
6
 
7
  def inference(img):
8
+ grayscale = skimage.color.rgb2gray(im)
9
+ binarized = np.where(grayscale>0.1, 1, 0)
10
+ processed = morphology.remove_small_objects(binarized.astype(bool), min_size=2, connectivity=2).astype(int)
11
+ out = processed
 
 
 
 
 
 
 
 
12
 
13
+ # black out pixels
14
+ #mask_x, mask_y = np.where(processed == 0)
15
+ #im[mask_x, mask_y, :3] = 0
 
16
 
 
 
 
17
 
18
  return out
19
 
 
24
  fn=inference,
25
  inputs='image',
26
  outputs='image',
27
+ title='Noise Removal w skimage',
28
+ description='Remove Noise with skimage.morphology!',
29
  examples=["detail_with_lines_and_noise.jpg", "lama.webp", "dT4KW.png"])
30
  #examples=["detail_with_lines_and_noise.jpg", "lama.webp", "test_lines.jpg","llama.jpg", "dT4KW.png"])
31