DasariHarshitha commited on
Commit
5661c60
Β·
verified Β·
1 Parent(s): 9b8663d

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +120 -0
  2. innomatics-footer-logo.png +0 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from PIL import Image
5
+ import io
6
+ import base64
7
+
8
+ st.set_page_config(page_title="Image Augmentation Tool 🧰", page_icon="πŸ–ΌοΈ", layout="centered")
9
+
10
+
11
+ def get_base64_image(image_path):
12
+ with open(image_path, "rb") as f:
13
+ data = f.read()
14
+ return base64.b64encode(data).decode()
15
+
16
+ image_base64 = get_base64_image("innomatics-footer-logo.png")
17
+
18
+ st.markdown(
19
+ f"""
20
+ <div style='text-align: center;'>
21
+ <img src="data:image/png;base64,{image_base64}" width="600" height="100">
22
+ </div>
23
+ """,
24
+ unsafe_allow_html=True
25
+ )
26
+
27
+ st.markdown("<h1 style='text-align: center;'>πŸ–ΌοΈ Image Augmentation Tool 🎨</h1>", unsafe_allow_html=True)
28
+ st.markdown("<h4 style='text-align: center;'>✨ Apply real-time transformations to your images</h4>", unsafe_allow_html=True)
29
+ st.markdown("---")
30
+
31
+ # Upload section
32
+ st.subheader("πŸ“€ Upload Your Image")
33
+ uploaded_file = st.file_uploader("Choose an image file (jpg, jpeg, png)", type=["jpg", "jpeg", "png"])
34
+
35
+ if uploaded_file is not None:
36
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
37
+ image = cv2.imdecode(file_bytes, 1)
38
+ original_image = image.copy()
39
+
40
+ # Sidebar options
41
+ st.sidebar.title("πŸ› οΈ Transformations Panel")
42
+ st.sidebar.markdown("πŸ”„ Choose your desired transformations below:")
43
+
44
+ grayscale = st.sidebar.checkbox("πŸ–€ Convert to Grayscale")
45
+ rotate_angle = st.sidebar.slider("πŸŒ€ Rotate", -180, 180, 0)
46
+ flip_horizontal = st.sidebar.checkbox("↔️ Flip Horizontally")
47
+ flip_vertical = st.sidebar.checkbox("↕️ Flip Vertically")
48
+ shear_factor = st.sidebar.slider("πŸ“ Shearing", -0.5, 0.5, 0.0, step=0.01)
49
+ translate_x = st.sidebar.slider("➑️ Translate X", -100, 100, 0)
50
+ translate_y = st.sidebar.slider("⬇️ Translate Y", -100, 100, 0)
51
+ crop = st.sidebar.checkbox("βœ‚οΈ Crop Image")
52
+
53
+ if crop:
54
+ crop_x = st.sidebar.slider("πŸ”² Crop Start X", 0, image.shape[1] - 1, 0)
55
+ crop_y = st.sidebar.slider("πŸ”³ Crop Start Y", 0, image.shape[0] - 1, 0)
56
+ crop_w = st.sidebar.slider("πŸ”² Crop Width", 1, image.shape[1] - crop_x, image.shape[1] - crop_x)
57
+ crop_h = st.sidebar.slider("πŸ”³ Crop Height", 1, image.shape[0] - crop_y, image.shape[0] - crop_y)
58
+
59
+ # Apply transformations
60
+ try:
61
+ if grayscale:
62
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
63
+ image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
64
+
65
+ if rotate_angle != 0:
66
+ (h, w) = image.shape[:2]
67
+ M = cv2.getRotationMatrix2D((w // 2, h // 2), rotate_angle, 1.0)
68
+ image = cv2.warpAffine(image, M, (w, h))
69
+
70
+ if flip_horizontal:
71
+ image = cv2.flip(image, 1)
72
+
73
+ if flip_vertical:
74
+ image = cv2.flip(image, 0)
75
+
76
+ if shear_factor != 0.0:
77
+ rows, cols, _ = image.shape
78
+ M = np.float32([
79
+ [1, shear_factor, 0],
80
+ [0, 1, 0]
81
+ ])
82
+ image = cv2.warpAffine(image, M, (cols, rows))
83
+
84
+ if translate_x != 0 or translate_y != 0:
85
+ M = np.float32([
86
+ [1, 0, translate_x],
87
+ [0, 1, translate_y]
88
+ ])
89
+ image = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
90
+
91
+ if crop:
92
+ image = image[crop_y:crop_y + crop_h, crop_x:crop_x + crop_w]
93
+
94
+ # Display results
95
+ st.subheader("πŸ” Preview")
96
+ col1, col2 = st.columns(2)
97
+ with col1:
98
+ st.image(original_image, caption="πŸ–ΌοΈ Original Image", use_container_width=True, channels="BGR")
99
+ with col2:
100
+ st.image(image, caption="✨ Transformed Image", use_container_width=True, channels="BGR")
101
+
102
+ # Download button
103
+ img_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
104
+ buf = io.BytesIO()
105
+ img_pil.save(buf, format="PNG")
106
+ byte_im = buf.getvalue()
107
+
108
+ st.download_button(
109
+ label="πŸ“₯ Download Transformed Image",
110
+ data=byte_im,
111
+ file_name="transformed_image.png",
112
+ mime="image/png"
113
+ )
114
+
115
+ except Exception as e:
116
+ st.error(f"🚨 Error: {e}")
117
+
118
+ else:
119
+ st.info("πŸ“Ž Please upload an image to begin.")
120
+
innomatics-footer-logo.png ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Pillow
2
+ streamlit
3
+ opencv-python
4
+ numpy
5
+ base64