Spaces:
Running
Running
File size: 1,474 Bytes
b39f801 fc9bdef fa19b50 8e64ae4 fa19b50 fc9bdef 7dce4c2 fc9bdef fa19b50 8e64ae4 fa19b50 fc9bdef 7dce4c2 d72f802 fc9bdef fa19b50 d72f802 |
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 |
import gradio as gr
import albumentations as A
import cv2
import numpy as np
def augment_image(image, flip=False, rotate=0, brightness=1.0, elastic=False, alpha=1.0, sigma=50):
image = np.array(image)
aug_list = []
if flip: aug_list.append(A.HorizontalFlip(p=1.0))
if rotate: aug_list.append(A.Rotate(limit=rotate, p=1.0))
if brightness != 1.0: aug_list.append(A.RandomBrightnessContrast(brightness_limit=(brightness-1, brightness-1), p=1.0))
if elastic: aug_list.append(A.ElasticTransform(alpha=alpha, sigma=sigma, alpha_affine=None, p=1.0))
aug = A.Compose(aug_list)
augmented = aug(image=image)
return augmented["image"]
def image_augmentor_interface(image, flip, rotate, brightness, elastic, alpha, sigma):
augmented_image = augment_image(image, flip, rotate, brightness, elastic, alpha, sigma)
return augmented_image
iface = gr.Interface(
fn=image_augmentor_interface,
inputs=[
gr.Image(type="numpy"),
gr.Checkbox(label="Flip Horizontally"),
gr.Slider(0, 360, label="Rotate Degrees"),
gr.Slider(0.5, 1.5, step=0.1, value=1, label="Brightness Adjustment"),
gr.Checkbox(label="Elastic Distortion"),
gr.Slider(1.0, 200.0, step=1.0, label="Elastic Alpha (distortion intensity)"),
gr.Slider(1.0, 100.0, step=1.0, label="Elastic Sigma (smoothness)")
],
outputs="image",
title="Image Augmentation with Gradio"
)
iface.launch(share=True)
|