maximuspowers commited on
Commit
d72f802
·
verified ·
1 Parent(s): fc9bdef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -4,7 +4,7 @@ import cv2
4
  import numpy as np
5
 
6
  # Function for image augmentation
7
- def augment_image(image, flip=False, rotate=0, brightness=1.0, noise=0, elastic=False):
8
  image = np.array(image)
9
 
10
  aug_list = []
@@ -21,7 +21,7 @@ def augment_image(image, flip=False, rotate=0, brightness=1.0, noise=0, elastic=
21
  aug_list.append(A.GaussNoise(var_limit=(noise, noise), p=1.0))
22
 
23
  if elastic:
24
- aug_list.append(A.ElasticTransform(alpha=1, sigma=50, alpha_affine=50, p=1.0))
25
 
26
  aug = A.Compose(aug_list)
27
  augmented = aug(image=image)
@@ -29,8 +29,8 @@ def augment_image(image, flip=False, rotate=0, brightness=1.0, noise=0, elastic=
29
  return augmented["image"]
30
 
31
  # Gradio Interface
32
- def image_augmentor_interface(image, flip, rotate, brightness, noise, elastic):
33
- augmented_image = augment_image(image, flip, rotate, brightness, noise, elastic)
34
  return augmented_image
35
 
36
  iface = gr.Interface(
@@ -41,10 +41,12 @@ iface = gr.Interface(
41
  gr.Slider(0, 360, label="Rotate Degrees"),
42
  gr.Slider(0.5, 1.5, step=0.1, label="Brightness Adjustment"),
43
  gr.Slider(0, 100, step=1, label="Noise Scale"),
44
- gr.Checkbox(label="Elastic Distortion")
 
 
45
  ],
46
  outputs="image",
47
  title="Image Augmentation with Gradio"
48
  )
49
 
50
- iface.launch()
 
4
  import numpy as np
5
 
6
  # Function for image augmentation
7
+ def augment_image(image, flip=False, rotate=0, brightness=1.0, noise=0, elastic=False, alpha=1.0, sigma=50):
8
  image = np.array(image)
9
 
10
  aug_list = []
 
21
  aug_list.append(A.GaussNoise(var_limit=(noise, noise), p=1.0))
22
 
23
  if elastic:
24
+ aug_list.append(A.ElasticTransform(alpha=alpha, sigma=sigma, alpha_affine=None, p=1.0))
25
 
26
  aug = A.Compose(aug_list)
27
  augmented = aug(image=image)
 
29
  return augmented["image"]
30
 
31
  # Gradio Interface
32
+ def image_augmentor_interface(image, flip, rotate, brightness, noise, elastic, alpha, sigma):
33
+ augmented_image = augment_image(image, flip, rotate, brightness, noise, elastic, alpha, sigma)
34
  return augmented_image
35
 
36
  iface = gr.Interface(
 
41
  gr.Slider(0, 360, label="Rotate Degrees"),
42
  gr.Slider(0.5, 1.5, step=0.1, label="Brightness Adjustment"),
43
  gr.Slider(0, 100, step=1, label="Noise Scale"),
44
+ gr.Checkbox(label="Elastic Distortion"),
45
+ gr.Slider(1.0, 200.0, step=1.0, label="Elastic Alpha (distortion intensity)"),
46
+ gr.Slider(1.0, 100.0, step=1.0, label="Elastic Sigma (smoothness)")
47
  ],
48
  outputs="image",
49
  title="Image Augmentation with Gradio"
50
  )
51
 
52
+ iface.launch(share=True)