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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -3,32 +3,21 @@ import albumentations as A
3
  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, alpha=1.0, sigma=50):
8
  image = np.array(image)
9
 
10
  aug_list = []
11
- if flip:
12
- aug_list.append(A.HorizontalFlip(p=1.0))
13
-
14
- if rotate:
15
- aug_list.append(A.Rotate(limit=rotate, p=1.0))
16
-
17
- if brightness != 1.0:
18
- aug_list.append(A.RandomBrightnessContrast(brightness_limit=(brightness-1, brightness-1), p=1.0))
19
-
20
- if noise > 0:
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)
28
 
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
@@ -39,7 +28,7 @@ iface = gr.Interface(
39
  gr.Image(type="numpy"),
40
  gr.Checkbox(label="Flip Horizontally"),
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)"),
 
3
  import cv2
4
  import numpy as np
5
 
 
6
  def augment_image(image, flip=False, rotate=0, brightness=1.0, noise=0, elastic=False, alpha=1.0, sigma=50):
7
  image = np.array(image)
8
 
9
  aug_list = []
10
+ if flip: aug_list.append(A.HorizontalFlip(p=1.0))
11
+ if rotate: aug_list.append(A.Rotate(limit=rotate, p=1.0))
12
+ if brightness != 1.0: aug_list.append(A.RandomBrightnessContrast(brightness_limit=(brightness-1, brightness-1), p=1.0))
13
+ if noise > 0: aug_list.append(A.GaussNoise(var_limit=(noise, noise), p=1.0))
14
+ if elastic: aug_list.append(A.ElasticTransform(alpha=alpha, sigma=sigma, alpha_affine=None, p=1.0))
 
 
 
 
 
 
 
 
 
15
 
16
  aug = A.Compose(aug_list)
17
  augmented = aug(image=image)
18
 
19
  return augmented["image"]
20
 
 
21
  def image_augmentor_interface(image, flip, rotate, brightness, noise, elastic, alpha, sigma):
22
  augmented_image = augment_image(image, flip, rotate, brightness, noise, elastic, alpha, sigma)
23
  return augmented_image
 
28
  gr.Image(type="numpy"),
29
  gr.Checkbox(label="Flip Horizontally"),
30
  gr.Slider(0, 360, label="Rotate Degrees"),
31
+ gr.Slider(0.5, 1.5, step=0.1, value=1, label="Brightness Adjustment"),
32
  gr.Slider(0, 100, step=1, label="Noise Scale"),
33
  gr.Checkbox(label="Elastic Distortion"),
34
  gr.Slider(1.0, 200.0, step=1.0, label="Elastic Alpha (distortion intensity)"),