File size: 1,996 Bytes
66ec950 87fe461 66ec950 6e61d26 66ec950 6e61d26 66ec950 6e61d26 66ec950 6e61d26 66ec950 6e61d26 66ec950 6e61d26 66ec950 6e61d26 66ec950 87fe461 6e61d26 87fe461 6e61d26 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import numpy as np
import os
import cv2
import json
import albumentations as A
import streamlit as st
from control import *
def load_image(image_name, path_to_folder="../images"):
path_to_image = os.path.join(path_to_folder, image_name)
image = cv2.imread(path_to_image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
return image
st.title("Demo of Albumentations transforms")
# selecting the image
path_to_images = "images"
image_names_list = [
x for x in os.listdir(path_to_images) if x[-3:] in ["jpg", "peg", "png"]
]
image_name = st.sidebar.selectbox("Select an image:", image_names_list)
image = load_image(image_name, path_to_images)
# selecting the transformation
path_to_config = "configs/augmentations.json"
with open(path_to_config, "r") as config_file:
augmentations = json.load(config_file)
transform_name = st.sidebar.selectbox(
"Select a transformation:", sorted(list(augmentations.keys()))
)
transform_params = augmentations[transform_name]
# show the transform options
if len(transform_params) == 0:
st.sidebar.text(transform_name + " transform has no parameters")
else:
for param in transform_params:
param["value"] = param2func[param["type"]](**param)
params_string = ", ".join(
[param["param_name"] + "=" + str(param["value"]) for param in transform_params]
+ ["p=1.0"]
)
params_string = "(" + params_string + ")"
st.text(transform_name + params_string)
st.text("Press R to update")
exec("transform = A." + transform_name + params_string)
st.image(
[image, transform(image=image)["image"]],
caption=["Original image", "Transformed image"],
width=320,
)
st.subheader("Docstring:")
st.text(str(transform.__doc__))
st.text("")
st.text("")
st.subheader("Credentials:")
st.text("Source: https://github.com/IliaLarchenko/albumentations-demo")
st.text("Albumentations library: https://github.com/albumentations-team/albumentations")
st.text("Image Source: https://www.pexels.com/royalty-free-images/")
|