Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import pandas as pd
|
|
| 4 |
import os
|
| 5 |
import zipfile
|
| 6 |
|
|
|
|
| 7 |
import cv2
|
| 8 |
|
| 9 |
st.markdown("""
|
|
@@ -97,24 +98,28 @@ def save_image_and_show(image, folder_name="output_images"):
|
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
-
def translation(img):
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
| 107 |
#st.image(img_trans_rgb, caption="Translation Applied", use_container_width=True)
|
| 108 |
|
| 109 |
-
def rotation(img):
|
|
|
|
| 110 |
#center = (width//2, height//2)
|
| 111 |
-
angle=90
|
|
|
|
| 112 |
r_x=img.shape[0]//2
|
| 113 |
r_y=img.shape[1]//2
|
| 114 |
-
rm=cv2.getRotationMatrix2D((r_y,r_x),angle,
|
| 115 |
r_img=cv2.warpAffine(img,rm,(img.shape[1],img.shape[0]))
|
| 116 |
-
img_rot_rgb = cv2.cvtColor(r_img, cv2.COLOR_BGR2RGB)
|
| 117 |
-
|
|
|
|
| 118 |
|
| 119 |
def scaling(img):
|
| 120 |
sx=2
|
|
@@ -162,6 +167,7 @@ if uploaded_file is not None:
|
|
| 162 |
# # Convert BGR to RGB as streamlit expects RGB colorspace
|
| 163 |
# img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 164 |
transformation = []
|
|
|
|
| 165 |
if trans and btn:
|
| 166 |
translation(img)
|
| 167 |
transformation.append("Translation")
|
|
|
|
| 4 |
import os
|
| 5 |
import zipfile
|
| 6 |
|
| 7 |
+
|
| 8 |
import cv2
|
| 9 |
|
| 10 |
st.markdown("""
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
+
def translation(img,n):
|
| 102 |
+
for i in range(n):
|
| 103 |
+
tx=np.random.randint(2,60)
|
| 104 |
+
ty=np.random.randint(2,55)
|
| 105 |
+
tm=np.array([[1,0,tx],[0,1,ty]],dtype=np.float32)
|
| 106 |
+
trans_img=cv2.warpAffine(img,tm,dsize=(img.shape[1],img.shape[0]),borderMode=cv2.BORDER_REFLECT)
|
| 107 |
+
img_trans_rgb = cv2.cvtColor(trans_img, cv2.COLOR_BGR2RGB)
|
| 108 |
+
save_image_and_show(img_trans_rgb)
|
| 109 |
#st.image(img_trans_rgb, caption="Translation Applied", use_container_width=True)
|
| 110 |
|
| 111 |
+
def rotation(img,n=5):
|
| 112 |
+
for i in range(n):
|
| 113 |
#center = (width//2, height//2)
|
| 114 |
+
angle=np.random.choice([90, 180, -90])
|
| 115 |
+
scale=np.round(np.random.uniform(1,2),2)
|
| 116 |
r_x=img.shape[0]//2
|
| 117 |
r_y=img.shape[1]//2
|
| 118 |
+
rm=cv2.getRotationMatrix2D((r_y,r_x),angle,scale)
|
| 119 |
r_img=cv2.warpAffine(img,rm,(img.shape[1],img.shape[0]))
|
| 120 |
+
#img_rot_rgb = cv2.cvtColor(r_img, cv2.COLOR_BGR2RGB)
|
| 121 |
+
save_image_and_show(r_img)
|
| 122 |
+
#st.image(img_rot_rgb, caption="Rotation Applied", use_container_width=True)
|
| 123 |
|
| 124 |
def scaling(img):
|
| 125 |
sx=2
|
|
|
|
| 167 |
# # Convert BGR to RGB as streamlit expects RGB colorspace
|
| 168 |
# img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 169 |
transformation = []
|
| 170 |
+
|
| 171 |
if trans and btn:
|
| 172 |
translation(img)
|
| 173 |
transformation.append("Translation")
|