Spaces:
Sleeping
Sleeping
File size: 2,956 Bytes
4a8795e b8e825d 30f1e62 4a8795e 78f92ee 0dbf7df 597c751 61d1760 c5b9e50 597c751 320f7da cc6872c 6bdaa8c 65c89e8 6b5d307 ae5f541 a6b6a75 6e7bcf4 c76f78d 6bdaa8c c6d3f67 0aa9785 0dbf7df 597c751 4a8795e 2394383 fae1918 2394383 fae1918 4a8795e ae5f541 4a8795e 6863937 4d9fb0f cc6872c 4a8795e 8addde4 |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import gradio
import cv2
import numpy as np
#num_inference_steps_slider_component_v1 = 121
#num_inference_steps_slider_component_v2 = 3
def inference(img, v1 = "121" , v2 = 9 ):
#out = cv2.erode(img,(15,15))
#out = cv2.dilate(out,(55,55))
# https://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.remove_small_objects
# my_result = cv2.remove_small_objects(binarized.astype(bool), min_size=2, connectivity=2).astype(int)
#img_bw = 255*(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) > 5).astype('uint8')
#se1 = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
#se2 = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
#mask = cv2.morphologyEx(img_bw, cv2.MORPH_CLOSE, se1)
#mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, se2)
#mask = np.dstack([mask, mask, mask]) / 255
#out = img * mask
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY ) # grayscale
#out = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,133,9)
#out = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,333,3)
out = cv2.GaussianBlur( gray ,(5,5),0)
# v1 121 , v2 1
#out = cv2.adaptiveThreshold( out ,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, int( float(v1) ) , int( float(v2) ) )
#out = cv2.adaptiveThreshold( out ,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 77 , int ( v2 ) )
out = cv2.adaptiveThreshold( out ,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 233 , 1 )
#out = blur = cv.GaussianBlur(img,(5,5),0)
#out = cv2.threshold(out,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
#kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernelSize)
#opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
return out
num_inference_steps_slider_component_v1 = gradio.Slider(
label="Number of inference steps",
info="The number of denoising steps. More denoising steps "
"usually lead to a higher quality image at the",
minimum=1,
maximum=500,
step=1,
value=121,
)
num_inference_steps_slider_component_v2 = gradio.Slider(
label="Number of inference steps",
info="The number of denoising steps. More denoising steps "
"usually lead to a higher quality image at the",
minimum=1,
maximum=100,
step=1,
value=3,
)
# 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',num_inference_steps_slider_component_v1,num_inference_steps_slider_component_v2],
outputs='image',
title='Noise Removal',
description='Remove Noise with OpenCV and Adaptial Gaussian!',
examples=[["detail_with_lines_and_noise.jpg", "lama.webp", "dT4KW.png"]]
)
#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()
|