File size: 1,912 Bytes
0bf753b
733d85c
0bf753b
9cbebf5
733d85c
 
 
 
b429418
733d85c
 
 
 
4a8795e
 
 
dd1c3e6
37e4718
ff5248c
efe3f24
 
 
 
5153767
ea89a71
fd89db2
 
33cb75c
efe3f24
 
a76dcb0
698bdd0
 
a76dcb0
 
c6d3f67
87a0c8f
de7f365
3ba8af6
 
08de328
68f192d
733d85c
0dbf7df
fd89db2
4a8795e
 
 
 
 
 
 
 
a76dcb0
 
cc6872c
 
4a8795e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio
import numpy as np


#import matplotlib.pyplot as plt
#from skimage import morphology,measure,feature
#from skimage.measure import label

import skimage

from skimage import restoration
from skimage.filters import threshold_otsu, rank
from skimage.morphology import closing, square, disk


def inference(img):
  gray = skimage.color.rgb2gray(img) # gray
  #binarized = np.where(grayscale>0.1, 1, 0)
  #processed = morphology.remove_small_objects(grayscale.astype(bool), min_size=33, connectivity=4).astype(int)
    
  #out = morphology.remove_small_objects(out , min_size=2, connectivity=4)
  #out = morphology.remove_small_holes(out , min_size=2, connectivity=4)

  #out = processed
  #edges = get_edges(img.copy())
  #edges = feature.canny(out, sigma=3) # edge detect via canny with sigma 3 
  #out = morphology.remove_small_objects(label(edges), 2,) # noise_reduced
  #out = morphology.remove_small_objects( out , 2,) # noise_reduced


  # black out pixels
  #mask_x, mask_y = np.where(processed == 0)
  #img[mask_x, mask_y, :3] = 0
  #mask_x, mask_y = np.where(processed == 0)
  #im[mask_x, mask_y, :3] = 0

  #denoise = restoration.denoise_tv_chambolle( out , weight=0.1)
  #thresh = threshold_otsu(denoise)
  #thresh = threshold_otsu(gray)
  thresh = 0.4
  #out = closing(denoise  > thresh, square(2))
  out =gray>thresh


  return out

# For information on Interfaces, head to https://gradio.app/docs/
# For user guides, head to https://gradio.app/guides/
# For Spaces usage, head to https://huggingface.co/docs/hub/spaces
iface = gradio.Interface(
  fn=inference,
  inputs='image',
  outputs='image',
  title='Noise Removal w skimage', 
  description='Remove Noise with skimage.morphology!',
  examples=["detail_with_lines_and_noise.jpg", "lama.webp", "dT4KW.png"])  
  #examples=["detail_with_lines_and_noise.jpg", "lama.webp", "test_lines.jpg","llama.jpg", "dT4KW.png"])  

iface.launch()