emilios commited on
Commit
df15d6d
·
verified ·
1 Parent(s): 4f0c19f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -9,9 +9,49 @@ def greet(image, in_contrast, in_brightness):
9
  # https://docs.opencv.org/4.x/d3/dc1/tutorial_basic_linear_transform.html
10
  new_image = cv2.convertScaleAbs(image, alpha=in_contrast, beta=in_brightness)
11
 
 
 
 
 
12
  return new_image
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  demo = gradio.Interface(
16
  fn=greet,
17
  inputs=['image', gradio.Slider(1,3), gradio.Slider(0, 100)],
 
9
  # https://docs.opencv.org/4.x/d3/dc1/tutorial_basic_linear_transform.html
10
  new_image = cv2.convertScaleAbs(image, alpha=in_contrast, beta=in_brightness)
11
 
12
+ # We create our gabor filters, and then apply them to our image
13
+ gfilters = create_gaborfilter()
14
+ new_image = apply_filter(new_image, gfilters)
15
+
16
  return new_image
17
 
18
+ def create_gaborfilter():
19
+ # This function is designed to produce a set of GaborFilters
20
+ # an even distribution of theta values equally distributed amongst pi rad / 180 degree
21
+
22
+ filters = []
23
+ num_filters = 16
24
+ ksize = 35 # The local area to evaluate
25
+ sigma = 3.0 # Larger Values produce more edges
26
+ lambd = 10.0
27
+ gamma = 0.5
28
+ psi = 0 # Offset value - lower generates cleaner results
29
+ for theta in np.arange(0, np.pi, np.pi / num_filters): # Theta is the orientation for edge detection
30
+ kern = cv2.getGaborKernel((ksize, ksize), sigma, theta, lambd, gamma, psi, ktype=cv2.CV_64F)
31
+ kern /= 1.0 * kern.sum() # Brightness normalization
32
+ filters.append(kern)
33
+ return filters
34
 
35
+ def apply_filter(img, filters):
36
+ # This general function is designed to apply filters to our image
37
+
38
+ # First create a numpy array the same size as our input image
39
+ newimage = np.zeros_like(img)
40
+
41
+ # Starting with a blank image, we loop through the images and apply our Gabor Filter
42
+ # On each iteration, we take the highest value (super impose), until we have the max value across all filters
43
+ # The final image is returned
44
+ depth = -1 # remain depth same as original image
45
+
46
+ for kern in filters: # Loop through the kernels in our GaborFilter
47
+ image_filter = cv2.filter2D(img, depth, kern) #Apply filter to image
48
+
49
+ # Using Numpy.maximum to compare our filter and cumulative image, taking the higher value (max)
50
+ np.maximum(newimage, image_filter, newimage)
51
+ return newimage
52
+
53
+
54
+
55
  demo = gradio.Interface(
56
  fn=greet,
57
  inputs=['image', gradio.Slider(1,3), gradio.Slider(0, 100)],