Spaces:
Running
Running
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) | |