dvj4's picture
Update app.py
94f4a6d verified
raw
history blame
1.82 kB
from PIL import Image
import numpy as np
import streamlit as st
from PIL import Image
import numpy as np
# Define function to process uploaded image
def process_image(image):
# Convert image to numpy array
img_array = np.array(image)
# Dummy sidewalk segmentation (replace with your actual segmentation algorithm)
patch_size = 128
step = 128
all_img_patches = []
for i in range(0, img_array.shape[0] - patch_size + 1, step):
for j in range(0, img_array.shape[1] - patch_size + 1, step):
single_patch_img = img_array[i:i + patch_size, j:j + patch_size]
all_img_patches.append(single_patch_img)
images = np.array(all_img_patches)
# Perform your actual image processing here
# Replace the code below with your segmentation algorithm or any other processing you need
# This is just a dummy example to show how to process the image
processed_images = []
for img in images:
processed_image = np.mean(img, axis=-1) # Example: Convert to grayscale
processed_images.append(processed_image)
processed_images = np.array(processed_images)
return processed_images
# Define Shiny app
def main():
st.title("Sidewalk Segmentation App")
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_image is not None:
# Display uploaded image
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Process uploaded image
with st.spinner("Processing..."):
segmentation_result = process_image(image)
# Display segmentation result
st.image(segmentation_result, caption="Sidewalk Segmentation Result", use_column_width=True)
if __name__ == "__main__":
main()