Spaces:
Sleeping
Sleeping
Update pages/3ML Project Life Cycle.py
Browse files
pages/3ML Project Life Cycle.py
CHANGED
|
@@ -1298,9 +1298,72 @@ cv2.destroyAllWindows()
|
|
| 1298 |
|
| 1299 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 1300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1301 |
|
| 1302 |
-
|
| 1303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
|
@@ -1320,11 +1383,6 @@ cv2.destroyAllWindows()
|
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
-
|
| 1324 |
-
|
| 1325 |
-
|
| 1326 |
-
|
| 1327 |
-
|
| 1328 |
#------------------------------------------------------ Projects ------------------------------------------
|
| 1329 |
elif st.session_state.page == "projects":
|
| 1330 |
|
|
|
|
| 1298 |
|
| 1299 |
st.markdown("<hr>", unsafe_allow_html=True)
|
| 1300 |
|
| 1301 |
+
|
| 1302 |
+
st.title("Interactive Image Augmentation Tool")
|
| 1303 |
+
|
| 1304 |
+
# Image upload
|
| 1305 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|
| 1306 |
+
if uploaded_file is not None:
|
| 1307 |
+
# Load the image
|
| 1308 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 1309 |
+
img = cv2.imdecode(file_bytes, 1)
|
| 1310 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 1311 |
+
st.image(img, caption="Uploaded Image", use_column_width=True)
|
| 1312 |
+
|
| 1313 |
+
# Choose operation
|
| 1314 |
+
st.markdown("### Choose Transformation")
|
| 1315 |
+
operation = st.selectbox(
|
| 1316 |
+
"Select the transformation you want to perform:",
|
| 1317 |
+
["None", "Cropping", "Scaling", "Translation", "Shearing", "Rotation"]
|
| 1318 |
+
)
|
| 1319 |
|
| 1320 |
+
if operation == "Cropping":
|
| 1321 |
+
st.markdown("### Cropping Parameters")
|
| 1322 |
+
x1 = st.number_input("X1 (Start Column)", min_value=0, value=0, step=1)
|
| 1323 |
+
y1 = st.number_input("Y1 (Start Row)", min_value=0, value=0, step=1)
|
| 1324 |
+
x2 = st.number_input("X2 (End Column)", min_value=x1 + 1, value=img.shape[1], step=1)
|
| 1325 |
+
y2 = st.number_input("Y2 (End Row)", min_value=y1 + 1, value=img.shape[0], step=1)
|
| 1326 |
+
if st.button("Apply Cropping"):
|
| 1327 |
+
cropped_img = img[y1:y2, x1:x2]
|
| 1328 |
+
st.image(cropped_img, caption="Cropped Image", use_column_width=True)
|
| 1329 |
+
|
| 1330 |
+
elif operation == "Scaling":
|
| 1331 |
+
st.markdown("### Scaling Parameters")
|
| 1332 |
+
scale_x = st.slider("Scale X", 0.1, 3.0, 1.0, step=0.1)
|
| 1333 |
+
scale_y = st.slider("Scale Y", 0.1, 3.0, 1.0, step=0.1)
|
| 1334 |
+
if st.button("Apply Scaling"):
|
| 1335 |
+
scaled_img = cv2.resize(img, None, fx=scale_x, fy=scale_y, interpolation=cv2.INTER_LINEAR)
|
| 1336 |
+
st.image(scaled_img, caption="Scaled Image", use_column_width=True)
|
| 1337 |
+
|
| 1338 |
+
elif operation == "Translation":
|
| 1339 |
+
st.markdown("### Translation Parameters")
|
| 1340 |
+
tx = st.slider("Shift X (pixels)", -img.shape[1], img.shape[1], 0)
|
| 1341 |
+
ty = st.slider("Shift Y (pixels)", -img.shape[0], img.shape[0], 0)
|
| 1342 |
+
if st.button("Apply Translation"):
|
| 1343 |
+
t_mat = np.float32([[1, 0, tx], [0, 1, ty]])
|
| 1344 |
+
translated_img = cv2.warpAffine(img, t_mat, (img.shape[1], img.shape[0]))
|
| 1345 |
+
st.image(translated_img, caption="Translated Image", use_column_width=True)
|
| 1346 |
+
|
| 1347 |
+
elif operation == "Shearing":
|
| 1348 |
+
st.markdown("### Shearing Parameters")
|
| 1349 |
+
sh_x = st.slider("Shear X", -2.0, 2.0, 0.0, step=0.1)
|
| 1350 |
+
sh_y = st.slider("Shear Y", -2.0, 2.0, 0.0, step=0.1)
|
| 1351 |
+
if st.button("Apply Shearing"):
|
| 1352 |
+
shear_mat = np.float32([[1, sh_x, 0], [sh_y, 1, 0]])
|
| 1353 |
+
sheared_img = cv2.warpAffine(img, shear_mat, (img.shape[1], img.shape[0]))
|
| 1354 |
+
st.image(sheared_img, caption="Sheared Image", use_column_width=True)
|
| 1355 |
+
|
| 1356 |
+
elif operation == "Rotation":
|
| 1357 |
+
st.markdown("### Rotation Parameters")
|
| 1358 |
+
angle = st.slider("Rotation Angle (degrees)", -360, 360, 0)
|
| 1359 |
+
if st.button("Apply Rotation"):
|
| 1360 |
+
center = (img.shape[1] // 2, img.shape[0] // 2)
|
| 1361 |
+
rot_mat = cv2.getRotationMatrix2D(center, angle, 1.0)
|
| 1362 |
+
rotated_img = cv2.warpAffine(img, rot_mat, (img.shape[1], img.shape[0]))
|
| 1363 |
+
st.image(rotated_img, caption="Rotated Image", use_column_width=True)
|
| 1364 |
+
|
| 1365 |
+
else:
|
| 1366 |
+
st.warning("Please upload an image file to continue.")
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
|
|
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1386 |
#------------------------------------------------------ Projects ------------------------------------------
|
| 1387 |
elif st.session_state.page == "projects":
|
| 1388 |
|