Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,19 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
import numpy as np
|
4 |
-
|
5 |
|
6 |
|
7 |
def inference(img):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
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 |
-
|
22 |
-
#
|
23 |
-
|
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
|
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 |
|