Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
if picture:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
blake_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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|