Spaces:
Runtime error
Runtime error
File size: 2,341 Bytes
eab34ad 15364a8 4ab77bb 3dc6831 df15d6d 9a23331 df15d6d 8980d86 e3a86b8 bf06697 df15d6d bf06697 c822ea5 9674c2e bf06697 df15d6d 843859b 9a23331 4f0c19f 2a01a01 843859b 9a23331 843859b 9a23331 15364a8 a4409f2 |
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 |
import gradio
import cv2
def create_gaborfilter():
# This function is designed to produce a set of GaborFilters
# an even distribution of theta values equally distributed amongst pi rad / 180 degree
filters = []
num_filters = 16
ksize = 35 # The local area to evaluate
sigma = 3.0 # Larger Values produce more edges
lambd = 10.0
gamma = 0.5
psi = 0 # Offset value - lower generates cleaner results
for theta in np.arange(0, np.pi, np.pi / num_filters): # Theta is the orientation for edge detection
kern = cv2.getGaborKernel((ksize, ksize), sigma, theta, lambd, gamma, psi, ktype=cv2.CV_64F)
kern /= 1.0 * kern.sum() # Brightness normalization
filters.append(kern)
return filters
def apply_filter(img, filters):
# This general function is designed to apply filters to our image
# First create a numpy array the same size as our input image
newimage = np.zeros_like(img)
# Starting with a blank image, we loop through the images and apply our Gabor Filter
# On each iteration, we take the highest value (super impose), until we have the max value across all filters
# The final image is returned
depth = -1 # remain depth same as original image
for kern in filters: # Loop through the kernels in our GaborFilter
image_filter = cv2.filter2D(img, depth, kern) #Apply filter to image
# Using Numpy.maximum to compare our filter and cumulative image, taking the higher value (max)
np.maximum(newimage, image_filter, newimage)
return newimage
def greet(image, in_contrast=1.15, in_brightness=20):
in_contrast = float(in_contrast)
in_brightness = float(in_brightness)
# contrast [1.0-3.0]
# brightness [0-100]
# https://docs.opencv.org/4.x/d3/dc1/tutorial_basic_linear_transform.html
new_image = cv2.convertScaleAbs(image, alpha=in_contrast, beta=in_brightness)
# We create our gabor filters, and then apply them to our image
# gfilters = create_gaborfilter()
# new_image = apply_filter(new_image, gfilters)
return new_image
iface = gradio.Interface(
fn=greet,
inputs=['image', gradio.Slider(1,3), gradio.Slider(0, 100)],
outputs=['image'],
examples=[['detail_with_lines_and_noise.jpg']],
)
iface.launch()
|