Spaces:
Runtime error
Runtime error
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() |