Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +39 -33
pages/Data Collection.py
CHANGED
|
@@ -1855,18 +1855,24 @@ elif st.session_state.current_page == "image_transformations":
|
|
| 1855 |
return transformed_images
|
| 1856 |
|
| 1857 |
# Streamlit App
|
| 1858 |
-
st.title("Affine
|
| 1859 |
-
st.write("Select a transformation and
|
| 1860 |
|
| 1861 |
-
#
|
| 1862 |
-
transformation
|
| 1863 |
-
|
| 1864 |
-
|
| 1865 |
-
|
| 1866 |
-
|
| 1867 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1868 |
if transformation:
|
| 1869 |
-
uploaded_file = st.file_uploader("Now, upload an image", type=["jpg", "jpeg", "png"])
|
| 1870 |
|
| 1871 |
if uploaded_file:
|
| 1872 |
# Read the uploaded file into a numpy array using OpenCV
|
|
@@ -1876,32 +1882,32 @@ elif st.session_state.current_page == "image_transformations":
|
|
| 1876 |
# Display the uploaded image
|
| 1877 |
st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Uploaded Image", use_container_width=True)
|
| 1878 |
|
| 1879 |
-
#
|
| 1880 |
-
|
| 1881 |
-
|
|
|
|
|
|
|
| 1882 |
|
| 1883 |
-
|
| 1884 |
-
|
|
|
|
| 1885 |
|
| 1886 |
-
|
|
|
|
|
|
|
| 1887 |
for i, img in enumerate(transformed_images):
|
| 1888 |
-
|
| 1889 |
-
|
| 1890 |
-
|
| 1891 |
-
|
| 1892 |
-
|
| 1893 |
-
|
| 1894 |
-
|
| 1895 |
-
|
| 1896 |
-
|
| 1897 |
-
|
| 1898 |
-
|
| 1899 |
-
|
| 1900 |
-
label=f"Download All {transformation} Images",
|
| 1901 |
-
data=zip_buffer,
|
| 1902 |
-
file_name=f"{transformation}_transformed_images.zip",
|
| 1903 |
-
mime="application/zip"
|
| 1904 |
-
)
|
| 1905 |
|
| 1906 |
col1, col2 = st.columns(2)
|
| 1907 |
with col1:
|
|
|
|
| 1855 |
return transformed_images
|
| 1856 |
|
| 1857 |
# Streamlit App
|
| 1858 |
+
st.title("Dynamic Affine Transformation Tool")
|
| 1859 |
+
st.write("Select a transformation type to proceed and learn how it works before uploading an image.")
|
| 1860 |
|
| 1861 |
+
# Provide guidance based on the selected transformation
|
| 1862 |
+
if transformation:
|
| 1863 |
+
if transformation == "Rotation":
|
| 1864 |
+
st.info("Rotation rotates the image around a fixed point. Angles are applied in steps of 10 degrees.")
|
| 1865 |
+
elif transformation == "Scaling":
|
| 1866 |
+
st.info("Scaling adjusts the size of the image. The scale factor increases incrementally.")
|
| 1867 |
+
elif transformation == "Translation":
|
| 1868 |
+
st.info("Translation shifts the image horizontally and vertically in small steps.")
|
| 1869 |
+
elif transformation == "Shearing":
|
| 1870 |
+
st.info("Shearing skews the image along the x-axis or y-axis, creating a slanted effect.")
|
| 1871 |
+
elif transformation == "Cropping":
|
| 1872 |
+
st.info("Cropping trims the image edges step by step to focus on a smaller region.")
|
| 1873 |
+
|
| 1874 |
if transformation:
|
| 1875 |
+
uploaded_file = st.file_uploader("Step 2: Now, upload an image", type=["jpg", "jpeg", "png"])
|
| 1876 |
|
| 1877 |
if uploaded_file:
|
| 1878 |
# Read the uploaded file into a numpy array using OpenCV
|
|
|
|
| 1882 |
# Display the uploaded image
|
| 1883 |
st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Uploaded Image", use_container_width=True)
|
| 1884 |
|
| 1885 |
+
# Automatically apply the transformation after upload
|
| 1886 |
+
transformed_images = apply_affine_transformation(image, transformation)
|
| 1887 |
+
|
| 1888 |
+
if transformed_images:
|
| 1889 |
+
st.write(f"Generated 10 images using {transformation}:")
|
| 1890 |
|
| 1891 |
+
# Display all transformed images
|
| 1892 |
+
for i, img in enumerate(transformed_images):
|
| 1893 |
+
st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), caption=f"{transformation} {i+1}", use_container_width=True)
|
| 1894 |
|
| 1895 |
+
# Create ZIP file for download
|
| 1896 |
+
zip_buffer = io.BytesIO()
|
| 1897 |
+
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
| 1898 |
for i, img in enumerate(transformed_images):
|
| 1899 |
+
# Save each image as bytes
|
| 1900 |
+
_, img_encoded = cv2.imencode('.jpg', img)
|
| 1901 |
+
zip_file.writestr(f"{transformation}_image_{i+1}.jpg", img_encoded.tobytes())
|
| 1902 |
+
|
| 1903 |
+
zip_buffer.seek(0)
|
| 1904 |
+
st.download_button(
|
| 1905 |
+
label=f"Download All {transformation} Images",
|
| 1906 |
+
data=zip_buffer,
|
| 1907 |
+
file_name=f"{transformation}_transformed_images.zip",
|
| 1908 |
+
mime="application/zip"
|
| 1909 |
+
)
|
| 1910 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1911 |
|
| 1912 |
col1, col2 = st.columns(2)
|
| 1913 |
with col1:
|