LakshmiHarika commited on
Commit
326887a
·
verified ·
1 Parent(s): c78b010

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. 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 Transformations with Selection First")
1859
- st.write("Select a transformation and then upload an image to apply it dynamically.")
1860
 
1861
- # Transformation Options
1862
- transformation = st.selectbox(
1863
- "Select a transformation:",
1864
- ["Rotation", "Scaling", "Translation", "Shearing", "Cropping"]
1865
- )
1866
-
1867
- # Image Uploader (Only appears after selection)
 
 
 
 
 
 
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
- # Apply Transformation
1880
- if st.button(f"Apply {transformation}"):
1881
- transformed_images = apply_affine_transformation(image, transformation)
 
 
1882
 
1883
- if transformed_images:
1884
- st.write(f"Generated 10 images using {transformation}:")
 
1885
 
1886
- # Display all transformed images
 
 
1887
  for i, img in enumerate(transformed_images):
1888
- st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), caption=f"{transformation} {i+1}", use_container_width=True)
1889
-
1890
- # Create ZIP file for download
1891
- zip_buffer = io.BytesIO()
1892
- with zipfile.ZipFile(zip_buffer, "w") as zip_file:
1893
- for i, img in enumerate(transformed_images):
1894
- # Save each image as bytes
1895
- _, img_encoded = cv2.imencode('.jpg', img)
1896
- zip_file.writestr(f"{transformation}_image_{i+1}.jpg", img_encoded.tobytes())
1897
-
1898
- zip_buffer.seek(0)
1899
- st.download_button(
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: