Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +48 -0
pages/Data Collection.py
CHANGED
|
@@ -1332,6 +1332,54 @@ elif st.session_state.current_page == "image_transformations":
|
|
| 1332 |
"https://huggingface.co/spaces/LakshmiHarika/MachineLearning/resolve/main/Images/affine_transformations.png",
|
| 1333 |
use_container_width=True)
|
| 1334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
|
|
|
| 1332 |
"https://huggingface.co/spaces/LakshmiHarika/MachineLearning/resolve/main/Images/affine_transformations.png",
|
| 1333 |
use_container_width=True)
|
| 1334 |
|
| 1335 |
+
# Explanation for Translation
|
| 1336 |
+
st.markdown("""
|
| 1337 |
+
<h3 style="color: #9400d3;">Translation</h3>
|
| 1338 |
+
""", unsafe_allow_html=True)
|
| 1339 |
+
|
| 1340 |
+
st.write("""
|
| 1341 |
+
**Translation** involves moving an image from one location to another along the x-axis, y-axis, or both. It adjusts the position of the image on the canvas without modifying its original content.
|
| 1342 |
+
|
| 1343 |
+
The transformation is performed using a translation matrix:
|
| 1344 |
+
""")
|
| 1345 |
+
|
| 1346 |
+
st.write("""
|
| 1347 |
+
The translation matrix is represented as:
|
| 1348 |
+
|
| 1349 |
+
[[1, 0, tx], [0, 1, ty]]
|
| 1350 |
+
|
| 1351 |
+
|
| 1352 |
+
Here:
|
| 1353 |
+
- **tx**: Specifies the shift along the x-axis (horizontal axis).
|
| 1354 |
+
- **ty**: Specifies the shift along the y-axis (vertical axis).
|
| 1355 |
+
|
| 1356 |
+
""")
|
| 1357 |
+
|
| 1358 |
+
st.code("""
|
| 1359 |
+
# Load the image
|
| 1360 |
+
img = cv2.imread('path_to_image.jpg')
|
| 1361 |
+
|
| 1362 |
+
# Define translation parameters
|
| 1363 |
+
tx = 100 # Shift 100 pixels along the x-axis
|
| 1364 |
+
ty = 50 # Shift 50 pixels along the y-axis
|
| 1365 |
+
|
| 1366 |
+
# Create the translation matrix
|
| 1367 |
+
translation_matrix = np.array([[1, 0, tx], [0, 1, ty]], dtype=np.float32)
|
| 1368 |
+
|
| 1369 |
+
# Apply translation
|
| 1370 |
+
translated_img = cv2.warpAffine(img, translation_matrix, (300, 300))
|
| 1371 |
+
|
| 1372 |
+
# Display the images
|
| 1373 |
+
cv2.imshow("Original Image", img)
|
| 1374 |
+
cv2.imshow("Translated Image", translated_img)
|
| 1375 |
+
cv2.waitKey(0)
|
| 1376 |
+
cv2.destroyAllWindows()
|
| 1377 |
+
""", language="python")
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
|
| 1381 |
+
|
| 1382 |
+
|
| 1383 |
|
| 1384 |
|
| 1385 |
|