swap1411 commited on
Commit
6a6aba3
·
verified ·
1 Parent(s): 1793224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -101,6 +101,9 @@ def process_image(image_path):
101
  # Load the image
102
  image = cv2.imread(image_path)
103
 
 
 
 
104
  # Resize segmentation mask to match the input image dimensions
105
  segmentation_mask_resized = cv2.resize(segmentation_mask, (image.shape[1], image.shape[0]))
106
 
@@ -110,14 +113,20 @@ def process_image(image_path):
110
  # Crop the segmented region based on the bounding box
111
  cropped_segment = image[int(y1):int(y2), int(x1):int(x2)]
112
 
 
 
 
113
  # Save the cropped segmented image
114
  cropped_image_path = 'output/cropped_segment.jpg'
115
  cv2.imwrite(cropped_image_path, cropped_segment)
116
  print(f"Cropped segmented image saved to {cropped_image_path}")
117
 
118
- st.image(cropped_segment, caption="Uploaded Image", use_column_width=True)
119
- # Return the cropped image
120
- return cropped_segment
 
 
 
121
 
122
  def transform_string(input_str):
123
  # Remove extra spaces and convert to lowercase
 
101
  # Load the image
102
  image = cv2.imread(image_path)
103
 
104
+ # Convert the image to RGB format
105
+ image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
106
+
107
  # Resize segmentation mask to match the input image dimensions
108
  segmentation_mask_resized = cv2.resize(segmentation_mask, (image.shape[1], image.shape[0]))
109
 
 
113
  # Crop the segmented region based on the bounding box
114
  cropped_segment = image[int(y1):int(y2), int(x1):int(x2)]
115
 
116
+ # Convert the cropped segment to RGB
117
+ cropped_segment_rgb = cv2.cvtColor(cropped_segment, cv2.COLOR_BGR2RGB)
118
+
119
  # Save the cropped segmented image
120
  cropped_image_path = 'output/cropped_segment.jpg'
121
  cv2.imwrite(cropped_image_path, cropped_segment)
122
  print(f"Cropped segmented image saved to {cropped_image_path}")
123
 
124
+ # Display the image in Streamlit
125
+ st.image(cropped_segment_rgb, caption="Uploaded Image (Cropped)", use_column_width=True)
126
+
127
+ # Return the cropped RGB image
128
+ return cropped_segment_rgb
129
+
130
 
131
  def transform_string(input_str):
132
  # Remove extra spaces and convert to lowercase