|
import os |
|
import streamlit as st |
|
import albumentations as A |
|
|
|
|
|
from utils import load_augmentations_config, get_path_to_the_image |
|
from visuals import ( |
|
show_transform_control, |
|
select_image, |
|
show_credentials, |
|
show_docstring, |
|
) |
|
|
|
|
|
path_to_images = get_path_to_the_image() |
|
if not os.path.isdir(path_to_images): |
|
st.title("There is no directory: " + path_to_images) |
|
else: |
|
status, image = select_image(path_to_images) |
|
if status == 0: |
|
st.title("Can't load image from: " + path_to_images) |
|
else: |
|
|
|
st.title("Demo of Albumentations") |
|
|
|
|
|
|
|
placeholder_params = { |
|
"image_width": image.shape[1], |
|
"image_height": image.shape[0], |
|
"image_half_width": int(image.shape[1] / 2), |
|
"image_half_height": int(image.shape[0] / 2), |
|
} |
|
|
|
|
|
augmentations = load_augmentations_config( |
|
placeholder_params, "configs/augmentations.json" |
|
) |
|
|
|
|
|
transform_name = st.sidebar.selectbox( |
|
"Select a transformation:", sorted(list(augmentations.keys())) |
|
) |
|
|
|
|
|
param_values = show_transform_control(augmentations[transform_name]) |
|
|
|
|
|
transform = getattr(A, transform_name)(**param_values) |
|
data = A.ReplayCompose([transform])(image=image) |
|
augmented_image = data["image"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
width_original = 400 |
|
width_transformed = int( |
|
width_original / image.shape[1] * augmented_image.shape[1] |
|
) |
|
|
|
st.image(image, caption="Original image", width=width_original) |
|
st.image(augmented_image, caption="Transformed image", width=width_transformed) |
|
|
|
|
|
st.code(str(transform)) |
|
show_docstring(transform) |
|
show_credentials() |
|
|