EngAbod commited on
Commit
dca702c
·
1 Parent(s): eab9944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
app.py CHANGED
@@ -1,33 +1,31 @@
1
  import streamlit as st
2
- import cv2
3
  import numpy as np
 
4
 
5
- # Function to create a Blake-style image with a circular center
6
  def create_blake_image(input_image):
7
- # Create a circular mask
8
- height, width, _ = input_image.shape
9
- mask = np.zeros((height, width, 3), dtype=np.uint8)
10
- center = (width // 2, height // 2)
11
- radius = min(center)
12
- cv2.circle(mask, center, radius, (255, 255, 255), thickness=-1)
13
-
14
- # Apply the circular mask to the input image
15
- circular_image = cv2.bitwise_and(input_image, mask)
16
-
17
- return circular_image
18
-
19
- # Streamlit app
20
- st.title("Blake Image with Circular Center")
21
- picture = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
 
 
 
 
22
 
23
  if picture:
24
- # Read the image
25
- input_image = cv2.imdecode(np.fromstring(picture.read(), np.uint8), 1)
26
-
27
- # Create the Blake-style image
28
- blake_image = create_blake_image(input_image)
29
-
30
- # Display the original and Blake-style images
31
- st.image([input_image, blake_image], caption=["Original Image", "Blake Image"], use_container_width=True)
32
-
33
- st.text("Upload an image to see the Blake-style transformation.")
 
1
  import streamlit as st
 
2
  import numpy as np
3
+ import cv2
4
 
 
5
  def create_blake_image(input_image):
6
+ # Load the image using OpenCV
7
+ img = cv2.imread(input_image)
8
+
9
+ # Get the shape of the original image
10
+ height, width, _ = img.shape
11
+
12
+ # Create a circular mask with the same shape
13
+ mask = np.zeros((height, width), dtype=np.uint8)
14
+ circle_center = (width // 2, height // 2)
15
+ circle_radius = min(width, height) // 2
16
+ cv2.circle(mask, circle_center, circle_radius, 255, thickness=-1)
17
+
18
+ # Apply the mask to the original image
19
+ result = cv2.bitwise_and(img, img, mask=mask)
20
+
21
+ return result
22
+
23
+ st.title("Blake-Style Image Converter")
24
+ picture = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
25
 
26
  if picture:
27
+ # Convert the uploaded image to a Blake-style image
28
+ blake_image = create_blake_image(picture)
29
+
30
+ # Display the result
31
+ st.image(blake_image, caption="Blake-Style Image", use_column_width=True)