Phaneendrabayi commited on
Commit
3d38330
·
verified ·
1 Parent(s): 9e399df

Update pages/Life_cycle_of_ML.py

Browse files
Files changed (1) hide show
  1. pages/Life_cycle_of_ML.py +88 -0
pages/Life_cycle_of_ML.py CHANGED
@@ -746,6 +746,91 @@ pd.DataFrame(flattened_image.reshape(1, -1))""",language="python")
746
  st.write("### Combined DataFrame from All Images")
747
  st.dataframe(all_image_data) # Display the combined DataFrame
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
 
750
 
751
  if 'page' not in st.session_state:
@@ -760,6 +845,9 @@ elif st.session_state.page == 'more':
760
  More()
761
  elif st.session_state.page == 'Table':
762
  table()
 
 
 
763
 
764
  st.markdown("---")
765
 
 
746
  st.write("### Combined DataFrame from All Images")
747
  st.dataframe(all_image_data) # Display the combined DataFrame
748
 
749
+ if st.button("About Affine Transformation"):
750
+ st.session_state.page = "Affine"
751
+
752
+
753
+ def affine_transformation_demo():
754
+ st.title("Affine Transformations and Cropping Demo")
755
+
756
+ st.write("Affine transformations are linear mapping methods that preserve points, straight lines, and planes. This demo showcases the following transformations:")
757
+ st.write("- **Translation**: Shifts the image in the x and y directions.")
758
+ st.write("- **Rotation**: Rotates the image around a center point.")
759
+ st.write("- **Scaling**: Enlarges or reduces the dimensions of the image.")
760
+ st.write("- **Shearing**: Slants the image along the x or y direction.")
761
+ st.write("- **Cropping**: Extracts a specific region of interest (ROI).")
762
+
763
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
764
+
765
+ if uploaded_file:
766
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
767
+ image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
768
+
769
+ st.image(image, caption="Original Image", use_column_width=True, channels="BGR")
770
+
771
+ transformation_type = st.selectbox(
772
+ "Select Transformation Type",
773
+ ("Translation", "Rotation", "Scaling", "Shearing", "Cropping")
774
+ )
775
+
776
+ rows, cols = image.shape[:2]
777
+
778
+ if transformation_type == "Translation":
779
+ st.write("### Applying Translation")
780
+ st.write("Translation shifts the image in the x and y directions. The transformation matrix is defined as:")
781
+ st.code("""
782
+ [[1, 0, tx],
783
+ [0, 1, ty]]
784
+ """, language="text")
785
+ translation_matrix = np.float32([[1, 0, 50], [0, 1, 50]]) # Shift by 50 pixels right and down
786
+ transformed_image = cv2.warpAffine(image, translation_matrix, (cols, rows))
787
+
788
+ elif transformation_type == "Rotation":
789
+ st.write("### Applying Rotation")
790
+ st.write("Rotation rotates the image around a center point by a specified angle. The transformation matrix is:")
791
+ st.code("""
792
+ [[cos(theta), -sin(theta), tx],
793
+ [sin(theta), cos(theta), ty]]
794
+ """, language="text")
795
+ center = (cols // 2, rows // 2)
796
+ rotation_matrix = cv2.getRotationMatrix2D(center, 45, 1) # Rotate by 45 degrees
797
+ transformed_image = cv2.warpAffine(image, rotation_matrix, (cols, rows))
798
+
799
+ elif transformation_type == "Scaling":
800
+ st.write("### Applying Scaling")
801
+ st.write("Scaling enlarges or reduces the image dimensions. The transformation matrix is:")
802
+ st.code("""
803
+ [[sx, 0, 0],
804
+ [ 0, sy, 0]]
805
+ """, language="text")
806
+ scaling_matrix = np.float32([[1.5, 0, 0], [0, 1.5, 0]]) # Scale by 1.5x
807
+ transformed_image = cv2.warpAffine(image, scaling_matrix, (int(cols * 1.5), int(rows * 1.5)))
808
+
809
+ elif transformation_type == "Shearing":
810
+ st.write("### Applying Shearing")
811
+ st.write("Shearing slants the image along the x or y direction. The transformation matrix is:")
812
+ st.code("""
813
+ [[1, shx, 0],
814
+ [shy, 1, 0]]
815
+ """, language="text")
816
+ shearing_matrix = np.float32([[1, 0.2, 0], [0.2, 1, 0]]) # Shear in both x and y directions
817
+ transformed_image = cv2.warpAffine(image, shearing_matrix, (cols, rows))
818
+
819
+ elif transformation_type == "Cropping":
820
+ st.write("### Applying Cropping")
821
+ st.write("Cropping extracts a specific region of interest (ROI) from the image without requiring a transformation matrix. Instead, slicing is used to select a portion of the image.")
822
+ x_start, x_end = cols // 4, 3 * cols // 4
823
+ y_start, y_end = rows // 4, 3 * rows // 4
824
+ transformed_image = image[y_start:y_end, x_start:x_end]
825
+
826
+ else:
827
+ transformed_image = image
828
+
829
+ if transformation_type == "Cropping":
830
+ st.image(transformed_image, caption="Cropped Image", use_column_width=True, channels="BGR")
831
+ else:
832
+ st.image(transformed_image, caption=f"Transformed Image ({transformation_type})", use_column_width=True, channels="BGR")
833
+
834
 
835
 
836
  if 'page' not in st.session_state:
 
845
  More()
846
  elif st.session_state.page == 'Table':
847
  table()
848
+ elif st.session_state.page == 'Affine':
849
+ affine_transformation_demo()
850
+
851
 
852
  st.markdown("---")
853