Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +15 -5
pages/Data Collection.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
# Define functions for individual pages
|
|
@@ -1656,6 +1659,8 @@ def Image_Augmentation_page():
|
|
| 1656 |
cv2.destroyAllWindows()
|
| 1657 |
""", language="python")
|
| 1658 |
|
|
|
|
|
|
|
| 1659 |
# Function to apply affine transformations
|
| 1660 |
def apply_affine_transformation(image, transformation_type):
|
| 1661 |
transformed_images = []
|
|
@@ -1678,8 +1683,9 @@ def Image_Augmentation_page():
|
|
| 1678 |
# Simple cropping: reduce the size incrementally
|
| 1679 |
x1, y1 = i * 5, i * 5
|
| 1680 |
x2, y2 = cols - i * 5, rows - i * 5
|
| 1681 |
-
|
| 1682 |
-
|
|
|
|
| 1683 |
continue # Skip warpAffine for cropping
|
| 1684 |
else:
|
| 1685 |
st.error("Invalid transformation type!")
|
|
@@ -1688,8 +1694,8 @@ def Image_Augmentation_page():
|
|
| 1688 |
transformed_image = cv2.warpAffine(image, M, (cols, rows))
|
| 1689 |
transformed_images.append(transformed_image)
|
| 1690 |
|
| 1691 |
-
|
| 1692 |
-
|
| 1693 |
# Streamlit App
|
| 1694 |
st.title("Dynamic Affine Transformation Tool")
|
| 1695 |
st.write("Select a transformation type to proceed and learn how it works before uploading an image.")
|
|
@@ -1729,7 +1735,7 @@ def Image_Augmentation_page():
|
|
| 1729 |
transformed_images = apply_affine_transformation(image, transformation)
|
| 1730 |
|
| 1731 |
if transformed_images:
|
| 1732 |
-
st.write(f"Generated
|
| 1733 |
|
| 1734 |
# Display all transformed images
|
| 1735 |
for i, img in enumerate(transformed_images):
|
|
@@ -1750,6 +1756,10 @@ def Image_Augmentation_page():
|
|
| 1750 |
file_name=f"{transformation}_transformed_images.zip",
|
| 1751 |
mime="application/zip"
|
| 1752 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1753 |
else:
|
| 1754 |
st.warning("Please select a valid transformation type to proceed.")
|
| 1755 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
+
import io
|
| 5 |
+
import zipfile
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
|
| 9 |
# Define functions for individual pages
|
|
|
|
| 1659 |
cv2.destroyAllWindows()
|
| 1660 |
""", language="python")
|
| 1661 |
|
| 1662 |
+
|
| 1663 |
+
|
| 1664 |
# Function to apply affine transformations
|
| 1665 |
def apply_affine_transformation(image, transformation_type):
|
| 1666 |
transformed_images = []
|
|
|
|
| 1683 |
# Simple cropping: reduce the size incrementally
|
| 1684 |
x1, y1 = i * 5, i * 5
|
| 1685 |
x2, y2 = cols - i * 5, rows - i * 5
|
| 1686 |
+
if x1 < x2 and y1 < y2: # Ensure cropping dimensions are valid
|
| 1687 |
+
transformed_image = image[y1:y2, x1:x2]
|
| 1688 |
+
transformed_images.append(transformed_image)
|
| 1689 |
continue # Skip warpAffine for cropping
|
| 1690 |
else:
|
| 1691 |
st.error("Invalid transformation type!")
|
|
|
|
| 1694 |
transformed_image = cv2.warpAffine(image, M, (cols, rows))
|
| 1695 |
transformed_images.append(transformed_image)
|
| 1696 |
|
| 1697 |
+
return transformed_images
|
| 1698 |
+
|
| 1699 |
# Streamlit App
|
| 1700 |
st.title("Dynamic Affine Transformation Tool")
|
| 1701 |
st.write("Select a transformation type to proceed and learn how it works before uploading an image.")
|
|
|
|
| 1735 |
transformed_images = apply_affine_transformation(image, transformation)
|
| 1736 |
|
| 1737 |
if transformed_images:
|
| 1738 |
+
st.write(f"Generated {len(transformed_images)} images using {transformation}:")
|
| 1739 |
|
| 1740 |
# Display all transformed images
|
| 1741 |
for i, img in enumerate(transformed_images):
|
|
|
|
| 1756 |
file_name=f"{transformation}_transformed_images.zip",
|
| 1757 |
mime="application/zip"
|
| 1758 |
)
|
| 1759 |
+
else:
|
| 1760 |
+
st.warning("No transformed images generated. Please check your transformation type.")
|
| 1761 |
+
else:
|
| 1762 |
+
st.warning("Please upload an image to proceed.")
|
| 1763 |
else:
|
| 1764 |
st.warning("Please select a valid transformation type to proceed.")
|
| 1765 |
|