IliaLarchenko commited on
Commit
66ec950
1 Parent(s): 28da246

the simplest version

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. configs/augmentations.json +9 -0
  3. images/parrot.jpg +0 -0
  4. src/main.py +66 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .ipynb_checkpoints
configs/augmentations.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "ToGray": [],
3
+ "ToSepia": [],
4
+ "Blur": [{"name" : "blur_limit",
5
+ "type" : "int_interval",
6
+ "limits" : [3, 100],
7
+ "defaults" : [3, 7]}
8
+ ]
9
+ }
images/parrot.jpg ADDED
src/main.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import os
3
+ import matplotlib.pyplot as plt
4
+ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
5
+ import cv2
6
+ import json
7
+
8
+ import albumentations as A
9
+ import streamlit as st
10
+
11
+
12
+ def load_image(image_name, path_to_folder = '../images'):
13
+ path_to_image = os.path.join(path_to_folder, image_name)
14
+ image = cv2.imread(path_to_image)
15
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
16
+ return image
17
+
18
+
19
+ def show_int_interval(name, limits, defaults, **kwargs):
20
+ min_max_interval = st.sidebar.slider(name, limits[0], limits[1], defaults)
21
+ return min_max_interval
22
+
23
+
24
+
25
+ # dict from param name to function showing this param
26
+ param2func = {
27
+ 'int_interval': show_int_interval
28
+ }
29
+
30
+
31
+
32
+ st.title('Demo of Albumentations transforms')
33
+
34
+
35
+ # selecting the image
36
+ path_to_images = 'images'
37
+ image_names_list = [x for x in os.listdir(path_to_images) if x[-3:] in ['jpg', 'peg', 'png']]
38
+ image_name = st.sidebar.selectbox('Select an image:', image_names_list)
39
+ image = load_image(image_name, path_to_images)
40
+
41
+
42
+ # selecting the transformation
43
+ path_to_config = 'configs/augmentations.json'
44
+ with open(path_to_config, 'r') as config_file:
45
+ augmentations = json.load(config_file)
46
+ transform_name = st.sidebar.selectbox('Select a transformation:', list(augmentations.keys()))
47
+ transform_params = augmentations[transform_name]
48
+
49
+
50
+ # show the transform options
51
+ if len(transform_params) == 0:
52
+ st.sidebar.text(transform_name + ' transform has no parameters')
53
+ else:
54
+ for param in transform_params:
55
+ param['value'] = param2func[param['type']](**param)
56
+
57
+
58
+ params_string = ','.join([param['name'] + '=' + str(param['value']) for param in transform_params] + ['p=1.0'])
59
+ params_string = '(' + params_string + ')'
60
+
61
+ st.text('Press R to update')
62
+ exec('transform = A.' + transform_name + params_string)
63
+ st.image([image, transform(image = image)['image']],
64
+ caption = ['Original image', 'Transformed image'],
65
+ width = 320)
66
+ st.text(str(transform.__doc__))