Phaneendrabayi commited on
Commit
77bdd96
·
verified ·
1 Parent(s): 6ec8643

Update pages/Life_cycle_of_ML.py

Browse files
Files changed (1) hide show
  1. pages/Life_cycle_of_ML.py +47 -61
pages/Life_cycle_of_ML.py CHANGED
@@ -749,7 +749,6 @@ pd.DataFrame(flattened_image.reshape(1, -1))""",language="python")
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
 
@@ -768,68 +767,55 @@ def affine_transformation_demo():
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
 
 
749
  if st.button("About Affine Transformation"):
750
  st.session_state.page = "Affine"
751
 
 
752
  def affine_transformation_demo():
753
  st.title("Affine Transformations and Cropping Demo")
754
 
 
767
 
768
  st.image(image, caption="Original Image", use_column_width=True, channels="BGR")
769
 
 
 
 
 
 
770
  rows, cols = image.shape[:2]
771
 
772
+ st.write("### Translation")
773
+ st.write("Translation shifts the image in the x and y directions. The transformation matrix is defined as:")
774
+ st.code("""
775
+ [[1, 0, tx],
776
+ [0, 1, ty]]
777
+ """, language="text")
778
+ translation_matrix = np.float32([[1, 0, 50], [0, 1, 50]]) # Shift by 50 pixels right and down
779
+ translated_image = cv2.warpAffine(image, translation_matrix, (cols, rows))
780
+ st.image(translated_image, caption="Translated Image", use_column_width=True, channels="BGR")
781
+
782
+ st.write("### Rotation")
783
+ st.write("Rotation rotates the image around a center point by a specified angle. The transformation matrix is:")
784
+ st.code("""
785
+ [[cos(theta), -sin(theta), tx],
786
+ [sin(theta), cos(theta), ty]]
787
+ """, language="text")
788
+ center = (cols // 2, rows // 2)
789
+ rotation_matrix = cv2.getRotationMatrix2D(center, 45, 1) # Rotate by 45 degrees
790
+ rotated_image = cv2.warpAffine(image, rotation_matrix, (cols, rows))
791
+ st.image(rotated_image, caption="Rotated Image", use_column_width=True, channels="BGR")
792
+
793
+ st.write("### Scaling")
794
+ st.write("Scaling enlarges or reduces the image dimensions. The transformation matrix is:")
795
+ st.code("""
796
+ [[sx, 0, 0],
797
+ [ 0, sy, 0]]
798
+ """, language="text")
799
+ scaling_matrix = np.float32([[1.5, 0, 0], [0, 1.5, 0]]) # Scale by 1.5x
800
+ scaled_image = cv2.warpAffine(image, scaling_matrix, (int(cols * 1.5), int(rows * 1.5)))
801
+ st.image(scaled_image, caption="Scaled Image", use_column_width=True, channels="BGR")
802
+
803
+ st.write("### Shearing")
804
+ st.write("Shearing slants the image along the x or y direction. The transformation matrix is:")
805
+ st.code("""
806
+ [[1, shx, 0],
807
+ [shy, 1, 0]]
808
+ """, language="text")
809
+ shearing_matrix = np.float32([[1, 0.2, 0], [0.2, 1, 0]]) # Shear in both x and y directions
810
+ sheared_image = cv2.warpAffine(image, shearing_matrix, (cols, rows))
811
+ st.image(sheared_image, caption="Sheared Image", use_column_width=True, channels="BGR")
812
+
813
+ st.write("### Cropping")
814
+ 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.")
815
+ x_start, x_end = cols // 4, 3 * cols // 4
816
+ y_start, y_end = rows // 4, 3 * rows // 4
817
+ cropped_image = image[y_start:y_end, x_start:x_end]
818
+ st.image(cropped_image, caption="Cropped Image", use_column_width=True, channels="BGR")
 
 
 
 
 
 
 
 
819
 
820
 
821