Phaneendrabayi commited on
Commit
7a05d07
·
verified ·
1 Parent(s): 534cbee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -32,31 +32,28 @@ def main():
32
  ("Translation", "Rotation", "Scaling", "Shearing", "Cropping")
33
  )
34
 
35
- # Declare a variable to store the transformed image
36
- transformed_image = None
37
-
38
  # Apply selected transformations
39
  if transform_option == "Translation":
40
  tx = st.sidebar.slider("Translate X (pixels)", -100, 100, 0)
41
  ty = st.sidebar.slider("Translate Y (pixels)", -100, 100, 0)
42
  if st.sidebar.button("Apply Translation"):
43
- transformed_image = apply_transformation(image, "Translation", tx=tx, ty=ty)
44
 
45
  elif transform_option == "Rotation":
46
  angle = st.sidebar.slider("Rotation Angle (degrees)", -180, 180, 0)
47
  if st.sidebar.button("Apply Rotation"):
48
- transformed_image = apply_transformation(image, "Rotation", angle=angle)
49
 
50
  elif transform_option == "Scaling":
51
  scale_factor = st.sidebar.slider("Scale Factor", 0.1, 3.0, 1.0, 0.1)
52
  if st.sidebar.button("Apply Scaling"):
53
- transformed_image = apply_transformation(image, "Scaling", scale=scale_factor)
54
 
55
  elif transform_option == "Shearing":
56
  shear_x = st.sidebar.slider("Shear X", -1.0, 1.0, 0.0, 0.1)
57
  shear_y = st.sidebar.slider("Shear Y", -1.0, 1.0, 0.0, 0.1)
58
  if st.sidebar.button("Apply Shearing"):
59
- transformed_image = apply_transformation(image, "Shearing", shear_x=shear_x, shear_y=shear_y)
60
 
61
  elif transform_option == "Cropping":
62
  x_start = st.sidebar.slider("Crop Start X", 0, cols, 0)
@@ -64,13 +61,7 @@ def main():
64
  y_start = st.sidebar.slider("Crop Start Y", 0, rows, 0)
65
  y_end = st.sidebar.slider("Crop End Y", 0, rows, rows)
66
  if st.sidebar.button("Apply Cropping"):
67
- transformed_image = apply_transformation(image, "Cropping", x_start=x_start, x_end=x_end, y_start=y_start, y_end=y_end)
68
-
69
- # Only display this button if there is a transformed image to review
70
- if transformed_image is not None:
71
- st.image(transformed_image, caption=f"Transformed {transform_option} Image", channels="BGR")
72
- if st.button("Confirm and Add to DataFrame"):
73
- add_to_dataframe(transformed_image, transform_option)
74
 
75
  # Display cumulative DataFrame if it's not empty
76
  if not st.session_state.combined_data.empty:
@@ -89,7 +80,7 @@ def main():
89
 
90
 
91
  def apply_transformation(image, transform_name, **kwargs):
92
- """Apply the selected transformation and return the transformed image."""
93
  rows, cols = image.shape[:2]
94
 
95
  if transform_name == "Translation":
@@ -116,7 +107,11 @@ def apply_transformation(image, transform_name, **kwargs):
116
  x_start, x_end, y_start, y_end = kwargs["x_start"], kwargs["x_end"], kwargs["y_start"], kwargs["y_end"]
117
  transformed_image = image[y_start:y_end, x_start:x_end]
118
 
119
- return transformed_image
 
 
 
 
120
 
121
 
122
  def add_to_dataframe(image, transform_name):
 
32
  ("Translation", "Rotation", "Scaling", "Shearing", "Cropping")
33
  )
34
 
 
 
 
35
  # Apply selected transformations
36
  if transform_option == "Translation":
37
  tx = st.sidebar.slider("Translate X (pixels)", -100, 100, 0)
38
  ty = st.sidebar.slider("Translate Y (pixels)", -100, 100, 0)
39
  if st.sidebar.button("Apply Translation"):
40
+ apply_transformation(image, "Translation", tx=tx, ty=ty)
41
 
42
  elif transform_option == "Rotation":
43
  angle = st.sidebar.slider("Rotation Angle (degrees)", -180, 180, 0)
44
  if st.sidebar.button("Apply Rotation"):
45
+ apply_transformation(image, "Rotation", angle=angle)
46
 
47
  elif transform_option == "Scaling":
48
  scale_factor = st.sidebar.slider("Scale Factor", 0.1, 3.0, 1.0, 0.1)
49
  if st.sidebar.button("Apply Scaling"):
50
+ apply_transformation(image, "Scaling", scale=scale_factor)
51
 
52
  elif transform_option == "Shearing":
53
  shear_x = st.sidebar.slider("Shear X", -1.0, 1.0, 0.0, 0.1)
54
  shear_y = st.sidebar.slider("Shear Y", -1.0, 1.0, 0.0, 0.1)
55
  if st.sidebar.button("Apply Shearing"):
56
+ apply_transformation(image, "Shearing", shear_x=shear_x, shear_y=shear_y)
57
 
58
  elif transform_option == "Cropping":
59
  x_start = st.sidebar.slider("Crop Start X", 0, cols, 0)
 
61
  y_start = st.sidebar.slider("Crop Start Y", 0, rows, 0)
62
  y_end = st.sidebar.slider("Crop End Y", 0, rows, rows)
63
  if st.sidebar.button("Apply Cropping"):
64
+ apply_transformation(image, "Cropping", x_start=x_start, x_end=x_end, y_start=y_start, y_end=y_end)
 
 
 
 
 
 
65
 
66
  # Display cumulative DataFrame if it's not empty
67
  if not st.session_state.combined_data.empty:
 
80
 
81
 
82
  def apply_transformation(image, transform_name, **kwargs):
83
+ """Apply the selected transformation and update the DataFrame with transformed image data."""
84
  rows, cols = image.shape[:2]
85
 
86
  if transform_name == "Translation":
 
107
  x_start, x_end, y_start, y_end = kwargs["x_start"], kwargs["x_end"], kwargs["y_start"], kwargs["y_end"]
108
  transformed_image = image[y_start:y_end, x_start:x_end]
109
 
110
+ # Display the transformed image
111
+ st.image(transformed_image, caption=f"{transform_name} Result", channels="BGR")
112
+
113
+ # Update DataFrame with the transformed image data
114
+ add_to_dataframe(transformed_image, transform_name)
115
 
116
 
117
  def add_to_dataframe(image, transform_name):