Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,8 +103,8 @@ def zip_file(folder_name="output_images"):
|
|
| 103 |
|
| 104 |
def translation(img,n):
|
| 105 |
for i in range(n):
|
| 106 |
-
tx=np.random.randint(2,
|
| 107 |
-
ty=np.random.randint(
|
| 108 |
tm=np.array([[1,0,tx],[0,1,ty]],dtype=np.float32)
|
| 109 |
trans_img=cv2.warpAffine(img,tm,dsize=(img.shape[1],img.shape[0]),borderMode=cv2.BORDER_REFLECT)
|
| 110 |
img_trans_rgb = cv2.cvtColor(trans_img, cv2.COLOR_BGR2RGB)
|
|
@@ -128,30 +128,38 @@ def scaling(img,n=5):
|
|
| 128 |
for i in range(n):
|
| 129 |
sx=np.round(np.random.uniform(1,1.6),2)
|
| 130 |
sy=np.round(np.random.uniform(1,1.6),2)
|
| 131 |
-
tx=np.random.randint(2,
|
| 132 |
-
ty=np.random.randint(1,
|
| 133 |
sm=np.array([[sx,0,tx],[0,sy,ty]],dtype=np.float32)
|
| 134 |
s_img=cv2.warpAffine(img,sm,(img.shape[1],img.shape[0]))
|
| 135 |
#img_scal_rgb=cv2.cvtColor(s_img,cv2.COLOR_BGR2RGB)
|
| 136 |
save_image_and_show(s_img)
|
| 137 |
#st.image(img_scal_rgb, caption="Scaling Applied", use_container_width=True)
|
| 138 |
|
| 139 |
-
def shearing(img):
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
# def save_image(image, folder_name="output_images"):
|
| 157 |
# if not os.path.exists(folder_name):
|
|
|
|
| 103 |
|
| 104 |
def translation(img,n):
|
| 105 |
for i in range(n):
|
| 106 |
+
tx=np.random.randint(2,50)
|
| 107 |
+
ty=np.random.randint(1,45)
|
| 108 |
tm=np.array([[1,0,tx],[0,1,ty]],dtype=np.float32)
|
| 109 |
trans_img=cv2.warpAffine(img,tm,dsize=(img.shape[1],img.shape[0]),borderMode=cv2.BORDER_REFLECT)
|
| 110 |
img_trans_rgb = cv2.cvtColor(trans_img, cv2.COLOR_BGR2RGB)
|
|
|
|
| 128 |
for i in range(n):
|
| 129 |
sx=np.round(np.random.uniform(1,1.6),2)
|
| 130 |
sy=np.round(np.random.uniform(1,1.6),2)
|
| 131 |
+
tx=np.random.randint(2,40)
|
| 132 |
+
ty=np.random.randint(1,30)
|
| 133 |
sm=np.array([[sx,0,tx],[0,sy,ty]],dtype=np.float32)
|
| 134 |
s_img=cv2.warpAffine(img,sm,(img.shape[1],img.shape[0]))
|
| 135 |
#img_scal_rgb=cv2.cvtColor(s_img,cv2.COLOR_BGR2RGB)
|
| 136 |
save_image_and_show(s_img)
|
| 137 |
#st.image(img_scal_rgb, caption="Scaling Applied", use_container_width=True)
|
| 138 |
|
| 139 |
+
def shearing(img,n=5):
|
| 140 |
+
for i in range(n):
|
| 141 |
+
sx=np.round(np.random.uniform(1,1.5),2)
|
| 142 |
+
shx=np.round(np.random.uniform(0,0.5),2)
|
| 143 |
+
tx=np.random.randint(2,40)
|
| 144 |
+
shy=np.round(np.random.uniform(0,0.5),2)
|
| 145 |
+
sy=np.round(np.random.uniform(0,0.5),2)
|
| 146 |
+
ty=np.random.randint(1,30)
|
| 147 |
+
shm=np.array([[sx,shx,tx],[shy,sy,ty]],dtype=np.float32)
|
| 148 |
+
img_all=cv2.warpAffine(img,shm,(img.shape[1],img.shape[0]))
|
| 149 |
+
save_image_and_show(imag_all)
|
| 150 |
+
#img_shear_rgb=cv2.cvtColor(img_all,cv2.COLOR_BGR2RGB)
|
| 151 |
+
#st.image(img_shear_rgb, caption="Shearing Applied", use_container_width=True)
|
| 152 |
+
|
| 153 |
+
def cropping(img,n=5):
|
| 154 |
+
for i in range(n):
|
| 155 |
+
x_1=np.random.randint(20,60)
|
| 156 |
+
y_1=np.random.randint(110,160)
|
| 157 |
+
x_2=np.random.randint(20,60)
|
| 158 |
+
y_2=np.random.randint(110,160)
|
| 159 |
+
img_crop=img[x_1:y_1,x_2:y_2]
|
| 160 |
+
save_image_and_show(img_crop)
|
| 161 |
+
# img_crop_rgb=cv2.cvtColor(img_crop,cv2.COLOR_BGR2RGB)
|
| 162 |
+
# st.image(img_crop_rgb, caption="Shearing Applied", use_container_width=True)
|
| 163 |
|
| 164 |
# def save_image(image, folder_name="output_images"):
|
| 165 |
# if not os.path.exists(folder_name):
|